@tbox.cn/app-module-shopping-guide 1.0.0-alpha.14 → 1.0.0-alpha.16

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,7 +1,6 @@
1
1
  // src/server/index.ts
2
- import { definePreTool, loadModuleSkills, getRequestContext } from "@tbox.cn/app-agent-sdk-server";
3
- import { Router } from "express";
4
- import { toMallQueryContext, withMallScopeFromQuery, mallSlot } from "@tbox.cn/app-contracts-mall";
2
+ import { definePreTool, loadModuleSkills } from "@tbox.cn/app-agent-sdk-server";
3
+ import { mallSlot } from "@tbox.cn/app-contracts-mall";
5
4
 
6
5
  // src/server/cards/product-list/meta.ts
7
6
  import { productListCardDataSchema } from "@tbox.cn/app-contracts-mall";
@@ -494,13 +493,18 @@ var DETAIL_DATA = {
494
493
  var samples2 = [
495
494
  {
496
495
  label: "\u95E8\u5E97\u8BE6\u60C5\xB7\u5B8C\u6574\u4FE1\u606F",
497
- note: "\u4F7F\u7528\u95E8\u5E97\u5BFC\u89C8\u4E2D\u7684\u661F\u5DF4\u514B\u8EAB\u4EFD\uFF0C\u8865\u5145\u5C01\u9762\u3001\u7B80\u4ECB\u3001\u670D\u52A1\u3001\u8425\u4E1A\u65F6\u95F4\u4E0E\u53CC\u52A8\u4F5C",
496
+ note: "\u4F7F\u7528\u95E8\u5E97\u5BFC\u89C8\u4E2D\u7684\u661F\u5DF4\u514B\u8EAB\u4EFD\uFF0C\u8865\u5145\u5C01\u9762\u3001\u7B80\u4ECB\u3001\u670D\u52A1\u3001\u8425\u4E1A\u65F6\u95F4\u4E0E\u53CC\u52A8\u4F5C\uFF1B\u5F53\u524D\u5546\u573A\u5DF2\u914D\u7F6E\u5BFC\u822A\u670D\u52A1\u65F6\u643A\u5E26 indoorNavigation\uFF08\u5B8C\u6574 HTTPS \u8DF3\u8F6C\u5730\u5740\uFF0C\u6837\u4F8B\u7528\u4E2D\u7ACB\u57DF\u540D\uFF09",
498
497
  group: "\u95E8\u5E97\u8BE6\u60C5",
499
- data: DETAIL_DATA
498
+ data: {
499
+ ...DETAIL_DATA,
500
+ indoorNavigation: {
501
+ url: "https://indoor-nav.example.cn/universal/#/ar_v4?sdk_version=v4&image_channel=1&third_id=demo-shop-1002"
502
+ }
503
+ }
500
504
  },
501
505
  {
502
506
  label: "\u95E8\u5E97\u8BE6\u60C5\xB7\u6700\u5C0F\u4FE1\u606F",
503
- note: "\u65E0\u5C01\u9762\u3001\u65E0\u95E8\u5E97\u56FE\u3001\u65E0\u7B80\u4ECB\u65F6\u4FDD\u6301\u7D27\u51D1\u7ED3\u6784",
507
+ note: "\u65E0\u5C01\u9762\u3001\u65E0\u95E8\u5E97\u56FE\u3001\u65E0\u7B80\u4ECB\u65F6\u4FDD\u6301\u7D27\u51D1\u7ED3\u6784\uFF08\u65E0 indoorNavigation = \u5F53\u524D\u5546\u573A\u672A\u914D\u7F6E\u5BA4\u5185\u5BFC\u822A\uFF0C\u7701\u7565\u5B57\u6BB5\uFF09",
504
508
  group: "\u95E8\u5E97\u8BE6\u60C5",
505
509
  data: {
506
510
  merchantId: "demo-shop-1012",
@@ -888,7 +892,7 @@ var meta_default11 = meta11;
888
892
  // src/server/tools/index.ts
889
893
  import { createTool, coerceStringifiedFields, requireToolRequestContext, withCardEmissionHint, internalTool } from "@tbox.cn/app-agent-sdk-server";
890
894
  import { z } from "zod";
891
- import { mallSubjectIdOf } from "@tbox.cn/app-contracts-mall";
895
+ import { mallSubjectIdOf, toMallQueryContext } from "@tbox.cn/app-contracts-mall";
892
896
 
893
897
  // src/server/ports/index.ts
894
898
  import {
@@ -1071,6 +1075,29 @@ function projectShopDetail(m, mallId, miniAppId) {
1071
1075
  };
1072
1076
  }
1073
1077
 
1078
+ // src/server/services/indoor-navigation.ts
1079
+ import { INDOOR_NAVIGATION_SERVICE, indoorNavigationUrlSchema } from "@tbox.cn/app-contracts-mall";
1080
+ function resolveIndoorNavigationService(ctx) {
1081
+ return ctx.services.resolve?.(INDOOR_NAVIGATION_SERVICE);
1082
+ }
1083
+ async function resolveIndoorNavigationUrl(ctx, mallId, merchantId) {
1084
+ if (!mallId || !merchantId) return void 0;
1085
+ const service = resolveIndoorNavigationService(ctx);
1086
+ if (!service) return void 0;
1087
+ try {
1088
+ const url = await service.resolveJumpUrl(mallId, merchantId);
1089
+ return typeof url === "string" && indoorNavigationUrlSchema.safeParse(url).success ? url : void 0;
1090
+ } catch (err) {
1091
+ const message = err instanceof Error ? err.message : String(err);
1092
+ console.warn(`[shopping-guide] indoor navigation resolve error mallId=${mallId} merchantId=${merchantId}: ${message}`);
1093
+ return void 0;
1094
+ }
1095
+ }
1096
+ async function withIndoorNavigationTarget(data, ctx, mallId) {
1097
+ const url = await resolveIndoorNavigationUrl(ctx, mallId, data.merchantId);
1098
+ return url ? { ...data, indoorNavigation: { url } } : data;
1099
+ }
1100
+
1074
1101
  // src/server/tools/index.ts
1075
1102
  var str = (desc) => z.string().describe(desc);
1076
1103
  var optionalStr = (desc) => z.string().optional().describe(desc);
@@ -1305,13 +1332,17 @@ function createShoppingGuideTools(opts) {
1305
1332
  inputSchema: z.object({ shopId: str("\u95E8\u5E97 ID\uFF08\u6765\u81EA\u641C\u7D22\u7ED3\u679C\u5361\uFF09") }),
1306
1333
  execute: exec(async (ports, _ctx, args, execCtx) => {
1307
1334
  console.warn(`[get-shop] input shopId="${args.shopId}"`);
1308
- const shop = await ports.shop.getShop(String(args.shopId), toContext(reqCtxOf(execCtx)));
1335
+ const queryCtx = toMallQueryContext(reqCtxOf(execCtx));
1336
+ const shop = await ports.shop.getShop(String(args.shopId), queryCtx);
1309
1337
  console.warn(`[get-shop] output found=${!!shop} name="${shop?.name ?? ""}"`);
1310
1338
  if (!shop) {
1311
1339
  return { summary: JSON.stringify({ error: "not_found" }) };
1312
1340
  }
1313
- const shopCtx = toContext(reqCtxOf(execCtx));
1314
- const data = projectShopDetail(shop, shopCtx.scope.mallId || void 0, shopCtx.scope.miniAppId || void 0);
1341
+ const data = await withIndoorNavigationTarget(
1342
+ projectShopDetail(shop, queryCtx.scope.mallId || void 0, queryCtx.scope.miniAppId || void 0),
1343
+ _ctx,
1344
+ queryCtx.scope.mallId || void 0
1345
+ );
1315
1346
  return withCards(
1316
1347
  data,
1317
1348
  "shop-detail",
@@ -1580,6 +1611,43 @@ function createShoppingGuideHandler() {
1580
1611
  };
1581
1612
  }
1582
1613
 
1614
+ // src/server/routes.ts
1615
+ import { getRequestContext } from "@tbox.cn/app-agent-sdk-server";
1616
+ import { Router } from "express";
1617
+ import { toMallQueryContext as toMallQueryContext2, withMallScopeFromQuery } from "@tbox.cn/app-contracts-mall";
1618
+ function createShoppingGuideRouter(ctx) {
1619
+ const router = Router();
1620
+ router.get("/shop-detail", async (req, res) => {
1621
+ const shopId = typeof req.query["shopId"] === "string" ? req.query["shopId"].trim() : "";
1622
+ if (!shopId) {
1623
+ res.status(400).json({ error: "shopId required" });
1624
+ return;
1625
+ }
1626
+ try {
1627
+ const reqCtx = getRequestContext(req);
1628
+ if (!reqCtx) {
1629
+ res.status(401).json({ error: "unauthorized" });
1630
+ return;
1631
+ }
1632
+ const scopedReqCtx = withMallScopeFromQuery(reqCtx, req.query);
1633
+ const ports = await resolveShoppingGuidePorts(scopedReqCtx, ctx);
1634
+ const queryCtx = toMallQueryContext2(scopedReqCtx);
1635
+ const shop = await ports.shop.getShop(shopId, queryCtx);
1636
+ if (!shop) {
1637
+ res.status(404).json({ error: "not_found" });
1638
+ return;
1639
+ }
1640
+ const data = await withIndoorNavigationTarget(projectShopDetail(shop), ctx, queryCtx.scope.mallId || void 0);
1641
+ res.json({ data });
1642
+ } catch (err) {
1643
+ const message = err instanceof Error ? err.message : String(err);
1644
+ console.warn(`[shopping-guide] shop-detail route error shopId=${shopId}: ${message}`);
1645
+ res.status(500).json({ error: "internal_error" });
1646
+ }
1647
+ });
1648
+ return router;
1649
+ }
1650
+
1583
1651
  // src/server/cards/index.ts
1584
1652
  var shoppingGuideCards = {
1585
1653
  "product-list": meta_default,
@@ -1692,41 +1760,15 @@ var serverModule = {
1692
1760
  mallBus.subscribe("member.level.changed", ({ userId }) => {
1693
1761
  void userId;
1694
1762
  });
1695
- const router = Router();
1696
- router.get("/shop-detail", async (req, res) => {
1697
- const shopId = typeof req.query["shopId"] === "string" ? req.query["shopId"].trim() : "";
1698
- if (!shopId) {
1699
- res.status(400).json({ error: "shopId required" });
1700
- return;
1701
- }
1702
- try {
1703
- const reqCtx = getRequestContext(req);
1704
- if (!reqCtx) {
1705
- res.status(401).json({ error: "unauthorized" });
1706
- return;
1707
- }
1708
- const scopedReqCtx = withMallScopeFromQuery(reqCtx, req.query);
1709
- const ports = await resolveShoppingGuidePorts(scopedReqCtx, ctx);
1710
- const queryCtx = toMallQueryContext(scopedReqCtx);
1711
- const shop = await ports.shop.getShop(shopId, queryCtx);
1712
- if (!shop) {
1713
- res.status(404).json({ error: "not_found" });
1714
- return;
1715
- }
1716
- res.json({ data: projectShopDetail(shop) });
1717
- } catch (err) {
1718
- const message = err instanceof Error ? err.message : String(err);
1719
- console.warn(`[shopping-guide] shop-detail route error shopId=${shopId}: ${message}`);
1720
- res.status(500).json({ error: "internal_error" });
1721
- }
1722
- });
1723
- ctx.routes.register("shopping-guide", router);
1763
+ ctx.routes.register("shopping-guide", createShoppingGuideRouter(ctx));
1724
1764
  }
1725
1765
  };
1726
1766
 
1727
1767
  export {
1728
1768
  resolveShoppingGuidePorts,
1769
+ INDOOR_NAVIGATION_SERVICE,
1729
1770
  createShoppingGuideTools,
1771
+ createShoppingGuideRouter,
1730
1772
  shoppingGuideCards,
1731
1773
  serverModule
1732
1774
  };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- export { ShoppingGuideToolIds, ShoppingGuideTools, createShoppingGuideTools, resolveShoppingGuidePorts, serverModule, shoppingGuideCards } from './server/index.js';
1
+ export { ShoppingGuideToolIds, ShoppingGuideTools, createShoppingGuideRouter, createShoppingGuideTools, resolveShoppingGuidePorts, serverModule, shoppingGuideCards } from './server/index.js';
2
2
  export { clientModule } from './client/index.js';
3
+ export { INDOOR_NAVIGATION_SERVICE, IndoorNavigationService } from '@tbox.cn/app-contracts-mall';
3
4
  import '@tbox.cn/app-agent-sdk-server';
4
5
  import '@mastra/core/tools';
5
6
  import '@tbox.cn/app-sdk-server';
6
7
  import '@tbox.cn/app-contracts';
7
8
  import 'zod';
8
- import '@tbox.cn/app-contracts-mall';
9
+ import 'express';
9
10
  import '@tbox.cn/app-agent-sdk-client';
package/dist/index.js CHANGED
@@ -1,14 +1,18 @@
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-7FQ2WYWY.js";
7
9
  import {
8
10
  clientModule
9
11
  } from "./chunk-MBJPTP72.js";
10
12
  export {
13
+ INDOOR_NAVIGATION_SERVICE,
11
14
  clientModule,
15
+ createShoppingGuideRouter,
12
16
  createShoppingGuideTools,
13
17
  resolveShoppingGuidePorts,
14
18
  serverModule,
@@ -6,6 +6,8 @@ import * as _tbox_cn_app_contracts from '@tbox.cn/app-contracts';
6
6
  import { RequestContext } from '@tbox.cn/app-contracts';
7
7
  import * as zod from 'zod';
8
8
  import { CatalogQueryPort, ShopDirectoryQueryPort, CommercialCategoryQueryPort, MallDirectoryQueryPort, NavigationPort } from '@tbox.cn/app-contracts-mall';
9
+ export { INDOOR_NAVIGATION_SERVICE, IndoorNavigationService } from '@tbox.cn/app-contracts-mall';
10
+ import { Router } from 'express';
9
11
 
10
12
  /** 11 卡 meta map(key 约定 = cardType) */
11
13
  declare const shoppingGuideCards: {
@@ -1387,6 +1389,13 @@ declare const shoppingGuideCards: {
1387
1389
  }>, "many">>;
1388
1390
  services: zod.ZodArray<zod.ZodString, "many">;
1389
1391
  promotionFacts: zod.ZodArray<zod.ZodString, "many">;
1392
+ indoorNavigation: zod.ZodOptional<zod.ZodObject<{
1393
+ url: zod.ZodString;
1394
+ }, "strip", zod.ZodTypeAny, {
1395
+ url: string;
1396
+ }, {
1397
+ url: string;
1398
+ }>>;
1390
1399
  coupons: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
1391
1400
  name: zod.ZodString;
1392
1401
  imageUrl: zod.ZodOptional<zod.ZodString>;
@@ -1533,6 +1542,9 @@ declare const shoppingGuideCards: {
1533
1542
  freeCouponClaimMode?: "DIRECT" | "REDIRECT" | undefined;
1534
1543
  offerRef?: string | undefined;
1535
1544
  }[] | undefined;
1545
+ indoorNavigation?: {
1546
+ url: string;
1547
+ } | undefined;
1536
1548
  }, {
1537
1549
  status: {
1538
1550
  code: "unknown" | "enabled" | "disabled";
@@ -1592,6 +1604,9 @@ declare const shoppingGuideCards: {
1592
1604
  freeCouponClaimMode?: "DIRECT" | "REDIRECT" | undefined;
1593
1605
  offerRef?: string | undefined;
1594
1606
  }[] | undefined;
1607
+ indoorNavigation?: {
1608
+ url: string;
1609
+ } | undefined;
1595
1610
  }>>;
1596
1611
  readonly 'category-list': _tbox_cn_app_contracts.CardMeta<zod.ZodObject<{
1597
1612
  categories: zod.ZodArray<zod.ZodObject<{
@@ -3017,6 +3032,16 @@ interface ShoppingGuidePorts {
3017
3032
  }
3018
3033
  declare function resolveShoppingGuidePorts(reqCtx: RequestContext, ctx: ServerContext): Promise<ShoppingGuidePorts>;
3019
3034
 
3035
+ /**
3036
+ * module-shopping-guide HTTP 数据路由(平台侧挂 'shopping-guide' 前缀 → /api/m/shopping-guide/*)。
3037
+ * GET /shop-detail?shopId=xxx[&mallId=xxx]:供客户端半屏 sheet 直接拉取完整门店详情数据,绕过 AI 对话链。
3038
+ * - mallId 可选:有值时注入 scope(生产),缺省时走本地兜底(开发/演示);
3039
+ * - 室内导航:与门店查询同一商场范围(同一 reqCtx 解析的 scope);与 get-shop 工具共用
3040
+ * withIndoorNavigationTarget 单点——无有效跳转目标省略字段,详情照常返回(增强面 fail-soft)。
3041
+ */
3042
+
3043
+ declare function createShoppingGuideRouter(ctx: ServerContext): Router;
3044
+
3020
3045
  declare const serverModule: {
3021
3046
  declaration: {
3022
3047
  moduleId: string;
@@ -4400,6 +4425,13 @@ declare const serverModule: {
4400
4425
  }>, "many">>;
4401
4426
  services: zod.ZodArray<zod.ZodString, "many">;
4402
4427
  promotionFacts: zod.ZodArray<zod.ZodString, "many">;
4428
+ indoorNavigation: zod.ZodOptional<zod.ZodObject<{
4429
+ url: zod.ZodString;
4430
+ }, "strip", zod.ZodTypeAny, {
4431
+ url: string;
4432
+ }, {
4433
+ url: string;
4434
+ }>>;
4403
4435
  coupons: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
4404
4436
  name: zod.ZodString;
4405
4437
  imageUrl: zod.ZodOptional<zod.ZodString>;
@@ -4546,6 +4578,9 @@ declare const serverModule: {
4546
4578
  freeCouponClaimMode?: "DIRECT" | "REDIRECT" | undefined;
4547
4579
  offerRef?: string | undefined;
4548
4580
  }[] | undefined;
4581
+ indoorNavigation?: {
4582
+ url: string;
4583
+ } | undefined;
4549
4584
  }, {
4550
4585
  status: {
4551
4586
  code: "unknown" | "enabled" | "disabled";
@@ -4605,6 +4640,9 @@ declare const serverModule: {
4605
4640
  freeCouponClaimMode?: "DIRECT" | "REDIRECT" | undefined;
4606
4641
  offerRef?: string | undefined;
4607
4642
  }[] | undefined;
4643
+ indoorNavigation?: {
4644
+ url: string;
4645
+ } | undefined;
4608
4646
  }>>;
4609
4647
  'category-list': _tbox_cn_app_contracts.CardMeta<zod.ZodObject<{
4610
4648
  categories: zod.ZodArray<zod.ZodObject<{
@@ -6008,4 +6046,4 @@ declare const serverModule: {
6008
6046
  register(ctx: ServerContext): void;
6009
6047
  };
6010
6048
 
6011
- export { type ShoppingGuideToolIds, type ShoppingGuideTools, createShoppingGuideTools, resolveShoppingGuidePorts, serverModule, shoppingGuideCards };
6049
+ export { type ShoppingGuideToolIds, type ShoppingGuideTools, createShoppingGuideRouter, createShoppingGuideTools, resolveShoppingGuidePorts, serverModule, shoppingGuideCards };
@@ -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-7FQ2WYWY.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.14",
3
+ "version": "1.0.0-alpha.16",
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-mall": "1.0.0-alpha.14",
23
- "@tbox.cn/app-contracts": "1.0.0-alpha.14",
24
- "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.14",
25
- "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.14"
22
+ "@tbox.cn/app-contracts": "1.0.0-alpha.16",
23
+ "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.16",
24
+ "@tbox.cn/app-contracts-mall": "1.0.0-alpha.16",
25
+ "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.16"
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.14"
31
+ "@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.16"
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",
@@ -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' // 知识库未接入,暂停
@@ -381,13 +382,22 @@ export function createShoppingGuideTools(opts: {
381
382
  inputSchema: z.object({ shopId: str('门店 ID(来自搜索结果卡)') }),
382
383
  execute: exec(async (ports, _ctx, args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
383
384
  console.warn(`[get-shop] input shopId="${args.shopId}"`);
384
- const shop = await ports.shop.getShop(String(args.shopId), toContext(reqCtxOf(execCtx)));
385
+ // 缺商场范围降级(与 /shop-detail HTTP 同语义):toMallQueryContext 宽松组合单源——
386
+ // 有 scope 时与 toContext 同构;无 scope 空 mallId 兜底(ports 'none' 走本地兜底),
387
+ // 详情照常返回、mallId/导航省略,不再整链失败(strict 语义保留给检索类工具)。
388
+ const queryCtx = toMallQueryContext(reqCtxOf(execCtx));
389
+ const shop = await ports.shop.getShop(String(args.shopId), queryCtx);
385
390
  console.warn(`[get-shop] output found=${!!shop} name="${shop?.name ?? ''}"`);
386
391
  if (!shop) {
387
392
  return { summary: JSON.stringify({ error: 'not_found' }) }; // 无 cards:不出卡
388
393
  }
389
- const shopCtx = toContext(reqCtxOf(execCtx));
390
- const data = projectShopDetail(shop, shopCtx.scope.mallId || undefined, shopCtx.scope.miniAppId || undefined);
394
+ // 室内导航(与 /shop-detail HTTP 共用 withIndoorNavigationTarget 单点):
395
+ // mallId = 门店查询同源 mall 范围;无有效跳转目标省略字段,详情照常返回(增强面 fail-soft)
396
+ const data = await withIndoorNavigationTarget(
397
+ projectShopDetail(shop, queryCtx.scope.mallId || undefined, queryCtx.scope.miniAppId || undefined),
398
+ _ctx,
399
+ queryCtx.scope.mallId || undefined,
400
+ );
391
401
  return withCards(
392
402
  data,
393
403
  'shop-detail',
@@ -0,0 +1,301 @@
1
+ /**
2
+ * 室内导航接入双链路验收(get-shop 工具 + GET /shop-detail HTTP 共用 withIndoorNavigationTarget 单点)。
3
+ * 覆盖风险 ≡ 验收点(docs/plans/indoor-navigation/technical-design.md):
4
+ * - 同一商场/门店 → 两入口 indoorNavigation.url 完全一致,shopDetailCardDataSchema 校验通过;
5
+ * - 两商场各自配置(mallId 查配置隔离);
6
+ * - 降级族:缺商场范围 / 商场未配置 / 服务未注册 / 服务异常 → 省略字段、详情照常返回;
7
+ * - merchantId 原值透传('001' 不归一)。
8
+ * 服务本尊归任务 1(ctx.services 注册表)——本文件以测试实现并行开发;任务 1 交付后接线联跑补真实配置结果。
9
+ */
10
+ import { describe, expect, it } from 'vitest';
11
+ import express from 'express';
12
+ import type { Express, Request, Response, NextFunction } from 'express';
13
+ import request from 'supertest';
14
+ import {
15
+ createIntegrationsRegistry,
16
+ createAuthStrategyRegistry,
17
+ createEnvironmentSecretProvider,
18
+ createInMemoryStateStore,
19
+ createServerContext,
20
+ createToolExecContext,
21
+ } from '@tbox.cn/app-agent-sdk-server';
22
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
23
+ import { shopDetailCardDataSchema } from '@tbox.cn/app-contracts-mall';
24
+ import type { RequestContext } from '@tbox.cn/app-contracts';
25
+ import { createShoppingGuideTools } from '../src/server/tools';
26
+ import { createShoppingGuideRouter } from '../src/server/routes';
27
+ import { projectShopDetail } from '../src/server/projections';
28
+ import {
29
+ INDOOR_NAVIGATION_SERVICE,
30
+ type IndoorNavigationService,
31
+ withIndoorNavigationTarget,
32
+ } from '../src/server/services/indoor-navigation';
33
+
34
+ /** 会话上下文:mall scope 注入(attributes 契约键——与 shopping-guide.test.ts 同源) */
35
+ const reqCtxOf = (mallId?: string): RequestContext => ({
36
+ identity: { userId: 'local_u1', source: 'local' },
37
+ ...(mallId ? { attributes: { mall: { miniAppId: 'app1', mallId } } } : {}),
38
+ });
39
+
40
+ /** 商场范围 mallId='001' 门店——锁原值透传(禁任何归一) */
41
+ const SHOP = {
42
+ merchantId: '001',
43
+ name: '示例奶茶',
44
+ logoUrl: undefined,
45
+ coverUrls: [],
46
+ brand: undefined,
47
+ businessCategories: ['餐饮'],
48
+ location: { displayText: 'A 栋 1 楼 101', buildingName: 'A 栋', floorName: '1 楼', unitName: '101' },
49
+ status: { code: 'enabled' as const, label: '营业中', observedAt: '2026-11-18T00:00:00Z' },
50
+ description: '奶茶饮品店',
51
+ contactInfo: undefined,
52
+ services: [],
53
+ promotionFacts: [],
54
+ };
55
+
56
+ const FIXTURE_PROVIDER = 'fixture';
57
+ const FIXTURE_PROVIDER_ID = 'fixture-shopping@1';
58
+ /** mall-1/mall-2 双实例注册(两商场配置隔离验证的解析基础);'*' 通配 = 缺范围请求也解析到
59
+ * 门店 stub(语义聚焦:缺范围时门店查询本身照常成功,仅导航省略——非 404/500 差错态) */
60
+ const SLOT_INSTANCES: Record<string, { enabled: boolean }> = {
61
+ 'mall-1': { enabled: true },
62
+ 'mall-2': { enabled: true },
63
+ '*': { enabled: true },
64
+ };
65
+
66
+ function buildServer(opts?: { indoor?: IndoorNavigationService }): ServerContext {
67
+ const registry = createIntegrationsRegistry({
68
+ integrations: {
69
+ services: Object.fromEntries(
70
+ ['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'].map((service) => [
71
+ service,
72
+ { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: SLOT_INSTANCES },
73
+ ]),
74
+ ),
75
+ },
76
+ catalog: {
77
+ providers: {
78
+ [FIXTURE_PROVIDER]: {
79
+ [FIXTURE_PROVIDER_ID]: {
80
+ provider: FIXTURE_PROVIDER,
81
+ implementation: FIXTURE_PROVIDER_ID,
82
+ credentialType: '-',
83
+ owner: 'fixture',
84
+ services: ['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'],
85
+ local: true,
86
+ },
87
+ },
88
+ },
89
+ services: {},
90
+ credentialTypes: {},
91
+ },
92
+ authStrategies: createAuthStrategyRegistry(),
93
+ secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
94
+ instanceIdOf: (scope) => scope.mallId ?? '',
95
+ });
96
+ registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) => {
97
+ const ports = {
98
+ catalog: { async searchProducts() { return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false }; }, async getProduct() { return null; }, async getFacets() { return { brands: [], categories: [], priceRanges: [], floors: [] }; } },
99
+ shop: { async searchShops() { return { items: [SHOP], page: 1, pageSize: 10, total: 1, hasMore: false }; }, async getShop() { return SHOP; } },
100
+ category: { async listCategories() { return []; } },
101
+ directory: { async getDirectory() { return null; } },
102
+ };
103
+ const SLOT_KEY_OF: Record<string, keyof typeof ports> = {
104
+ 'shopping-guide.catalog': 'catalog',
105
+ 'shopping-guide.shops': 'shop',
106
+ 'shopping-guide.categories': 'category',
107
+ 'shopping-guide.directory': 'directory',
108
+ };
109
+ return ports[SLOT_KEY_OF[input.service] ?? 'directory'];
110
+ });
111
+ const serverCtx = createServerContext({ state: createInMemoryStateStore(), integrations: registry });
112
+ if (opts?.indoor) serverCtx.services.register(INDOOR_NAVIGATION_SERVICE, opts.indoor);
113
+ return serverCtx;
114
+ }
115
+
116
+ interface NavCall { mallId: string; merchantId: string }
117
+
118
+ /** 导航服务测试实现(并行开发替身——任务 1 交付后换其注册实现):
119
+ * mallId → 爱笔 H5 基址(未配置商场缺席);生成完整 URL 时追加 third_id=<merchantId>(编码一次)。 */
120
+ function makeIndoorStub(configs: Record<string, string>, overrides?: Partial<IndoorNavigationService>) {
121
+ const calls: NavCall[] = [];
122
+ const service: IndoorNavigationService = {
123
+ async resolveJumpUrl(mallId, merchantId) {
124
+ calls.push({ mallId, merchantId });
125
+ const base = configs[mallId];
126
+ if (!base) return undefined;
127
+ const joiner = base.includes('?') ? '&' : '?';
128
+ return `${base}${joiner}third_id=${encodeURIComponent(merchantId)}`;
129
+ },
130
+ ...overrides,
131
+ };
132
+ return { service, calls };
133
+ }
134
+
135
+ const MALL_1_URL = 'https://indoor-nav.example.cn/mall-1/#/ar_v4?sdk_version=v4';
136
+ const MALL_2_URL = 'https://indoor-nav.example.cn/mall-2/#/ar_v4?sdk_version=v4';
137
+
138
+ /** 工具链 get-shop 结果(shop-detail 卡数据) */
139
+ async function runGetShopTool(serverCtx: ServerContext, mallId: string | undefined) {
140
+ const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
141
+ return (await tools.getShop.execute!({ shopId: '001' }, createToolExecContext(reqCtxOf(mallId)) as never)) as {
142
+ summary: string;
143
+ cards?: { cardType: string; data: unknown }[];
144
+ };
145
+ }
146
+
147
+ /** HTTP 链 GET /shop-detail 结果 */
148
+ function makeHttpApp(serverCtx: ServerContext, reqCtx: RequestContext | undefined): Express {
149
+ const app = express();
150
+ app.use((req: Request, _res: Response, next: NextFunction) => {
151
+ if (reqCtx) (req as unknown as Record<string, unknown>)['tboxAuthContext'] = reqCtx;
152
+ next();
153
+ });
154
+ app.use(createShoppingGuideRouter(serverCtx));
155
+ return app;
156
+ }
157
+
158
+ describe('双链路一致:同一商场/门店 HTTP 与对话出卡返回同一 indoorNavigation.url', () => {
159
+ it('契约三件具名可达(合流防线:运行时出口漏导出时本断言先红)', async () => {
160
+ // 背景:contracts-mall 运行时入口(runtime.ts/dist)是 NAMED 导出面——新常量漏挂时
161
+ // 消费侧 import 得 undefined、register/resolve 两端同键假绿(stage P4.6b 曾拦截)。
162
+ const contracts = await import('@tbox.cn/app-contracts-mall');
163
+ expect(contracts.INDOOR_NAVIGATION_SERVICE).toBe('indoor-navigation');
164
+ expect((await import('../src/server/services/indoor-navigation')).INDOOR_NAVIGATION_SERVICE).toBe('indoor-navigation');
165
+ expect(typeof contracts.indoorNavigationUrlSchema).toBe('object');
166
+ expect(contracts.indoorNavigationUrlSchema.safeParse('https://').success).toBe(false);
167
+ expect(contracts.indoorNavigationUrlSchema.safeParse('https://nav.example.cn/ar?third_id=001').success).toBe(true);
168
+ });
169
+
170
+ it('get-shop 工具:卡数据携带 indoorNavigation.url 且 shopDetailCardDataSchema 通过', async () => {
171
+ const { service } = makeIndoorStub({ 'mall-1': MALL_1_URL });
172
+ const serverCtx = buildServer({ indoor: service });
173
+ const result = await runGetShopTool(serverCtx, 'mall-1');
174
+ expect(result.cards?.[0]?.cardType).toBe('shop-detail');
175
+ const data = result.cards![0]!.data;
176
+ expect(() => shopDetailCardDataSchema.parse(data)).not.toThrow();
177
+ const parsed = shopDetailCardDataSchema.parse(data);
178
+ expect(parsed.indoorNavigation?.url).toBe(`${MALL_1_URL}&third_id=001`);
179
+ });
180
+
181
+ it('HTTP /shop-detail:data.indoorNavigation.url 与工具链完全一致(同一 URL 字符串)', async () => {
182
+ const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
183
+ const serverCtx = buildServer({ indoor: service });
184
+ const toolResult = await runGetShopTool(serverCtx, 'mall-1');
185
+ const toolData = shopDetailCardDataSchema.parse(toolResult.cards![0]!.data);
186
+
187
+ const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
188
+ const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
189
+ expect(res.status).toBe(200);
190
+ const httpData = shopDetailCardDataSchema.parse(res.body.data);
191
+ expect(httpData.indoorNavigation?.url).toBe(toolData.indoorNavigation?.url);
192
+ expect(httpData.indoorNavigation).toEqual(toolData.indoorNavigation);
193
+ // 商场范围同源:工具经 scope、HTTP 经 query mallId 注入后同达 mall-1
194
+ expect(calls.every((c) => c.mallId === 'mall-1')).toBe(true);
195
+ });
196
+
197
+ it('门店标识原值透传:merchantId "001" 原样达导航服务(无归一/无前缀)', async () => {
198
+ const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
199
+ const serverCtx = buildServer({ indoor: service });
200
+ await runGetShopTool(serverCtx, 'mall-1');
201
+ expect(calls).toEqual([{ mallId: 'mall-1', merchantId: '001' }]);
202
+ });
203
+ });
204
+
205
+ describe('两商场各自配置:mallId 查配置隔离', () => {
206
+ it('mall-1/mall-2 → 各自基址生成的不同 URL', async () => {
207
+ const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL, 'mall-2': MALL_2_URL });
208
+ const serverCtx = buildServer({ indoor: service });
209
+ const r1 = shopDetailCardDataSchema.parse((await runGetShopTool(serverCtx, 'mall-1')).cards![0]!.data);
210
+ const r2 = shopDetailCardDataSchema.parse((await runGetShopTool(serverCtx, 'mall-2')).cards![0]!.data);
211
+ expect(r1.indoorNavigation?.url).toBe(`${MALL_1_URL}&third_id=001`);
212
+ expect(r2.indoorNavigation?.url).toBe(`${MALL_2_URL}&third_id=001`);
213
+ expect(calls.map((c) => c.mallId)).toEqual(['mall-1', 'mall-2']);
214
+ });
215
+
216
+ it('未配置商场(任务 1 返回 undefined)→ 省略字段,详情照常返回且 schema 通过', async () => {
217
+ const { service } = makeIndoorStub({ 'mall-1': MALL_1_URL }); // mall-2 未配置
218
+ const serverCtx = buildServer({ indoor: service });
219
+ const result = await runGetShopTool(serverCtx, 'mall-2');
220
+ const parsed = shopDetailCardDataSchema.parse(result.cards![0]!.data);
221
+ expect(parsed.indoorNavigation).toBeUndefined();
222
+ expect(parsed.name).toBe('示例奶茶');
223
+ expect(parsed.merchantId).toBe('001');
224
+ });
225
+ });
226
+
227
+ describe('降级族:缺范围/未注册/异常 → 省略字段,详情照常', () => {
228
+ it('HTTP 缺商场范围(无 mallId query/属性)→ 200 + 无 indoorNavigation + 不触达导航服务', async () => {
229
+ const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
230
+ const serverCtx = buildServer({ indoor: service });
231
+ const app = makeHttpApp(serverCtx, reqCtxOf());
232
+ const res = await request(app).get('/shop-detail?shopId=001');
233
+ expect(res.status).toBe(200);
234
+ const parsed = shopDetailCardDataSchema.parse(res.body.data);
235
+ expect(parsed.indoorNavigation).toBeUndefined();
236
+ expect(parsed.name).toBe('示例奶茶');
237
+ expect(calls).toEqual([]); // 缺范围先于服务调用短路
238
+ });
239
+
240
+ it('get-shop 工具缺商场范围 → 降级返回门店详情(不再「暂时无法查询」)+ 省略导航字段', async () => {
241
+ const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
242
+ const serverCtx = buildServer({ indoor: service });
243
+ // 和 HTTP 缺范围用例同场景:attributes 无 mall scope(fixture '*' 通配让门店查询本身成功,
244
+ // 聚焦锁工具层降级语义——此前 toContext throw → exec 兜底「暂时无法查询」整链失败)
245
+ const result = await runGetShopTool(serverCtx, undefined);
246
+ expect(result.cards?.[0]?.cardType).toBe('shop-detail'); // 原行为:无 cards
247
+ const parsed = shopDetailCardDataSchema.parse(result.cards![0]!.data);
248
+ expect(parsed.indoorNavigation).toBeUndefined();
249
+ expect(parsed.name).toBe('示例奶茶');
250
+ expect(parsed.mallId).toBeUndefined(); // 无范围不透传 mallId
251
+ expect(calls).toEqual([]); // 装饰单点缺范围先短路,不触达服务
252
+ });
253
+
254
+ it('HTTP 服务未注册 → 200 + 无 indoorNavigation(两级缺席同形)', async () => {
255
+ const serverCtx = buildServer(); // 不注册 indoor-navigation
256
+ const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
257
+ const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
258
+ expect(res.status).toBe(200);
259
+ expect(shopDetailCardDataSchema.parse(res.body.data).indoorNavigation).toBeUndefined();
260
+ });
261
+
262
+ it('HTTP 服务异常 → 200 + 无 indoorNavigation(增强面 fail-soft,不 500)', async () => {
263
+ const { service } = makeIndoorStub({}, { resolveJumpUrl: async () => { throw new Error('down'); } });
264
+ const serverCtx = buildServer({ indoor: service });
265
+ const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
266
+ const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
267
+ expect(res.status).toBe(200);
268
+ expect(shopDetailCardDataSchema.parse(res.body.data).indoorNavigation).toBeUndefined();
269
+ expect(res.body.data).toHaveProperty('name', '示例奶茶');
270
+ });
271
+
272
+ it('残缺/非法地址三层拦截:契约拒收 https:// → 消费侧同源 safeParse 省略 → 两条入口同形', async () => {
273
+ // ① 契约层:indoorNavigation.url 须为完整 HTTPS URL(indoorNavigationUrlSchema——url()+startsWith,
274
+ // 区别于仅前缀的 httpsUrlSchema;'https://' 残缺、非 https、裸文本均拒)
275
+ const base = projectShopDetail(SHOP as never);
276
+ expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'https://' } }).success).toBe(false);
277
+ expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'http://insecure.example.cn/nav' } }).success).toBe(false);
278
+ expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'not-a-url' } }).success).toBe(false);
279
+ expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'https://nav.example.cn/ar_v4?third_id=001' } }).success).toBe(true);
280
+
281
+ // ② 消费侧:服务返回残缺/非法地址 → 省略字段(复用契约同一 schema safeParse——防「服务下发了
282
+ // schema 过不去的地址」两侧判定漂移)
283
+ for (const url of ['https://', 'http://insecure.example.cn/nav', 'https:/single-slash.example.cn', 'not-a-url']) {
284
+ const serverCtx = buildServer();
285
+ serverCtx.services.register(INDOOR_NAVIGATION_SERVICE, { resolveJumpUrl: async () => url });
286
+ const data = await withIndoorNavigationTarget(projectShopDetail(SHOP as never), serverCtx, 'mall-1');
287
+ expect(data.indoorNavigation, `url=${url}`).toBeUndefined();
288
+ expect(data.name).toBe('示例奶茶');
289
+ }
290
+
291
+ // ③ 按 R2 试接证词回归:服务被配置成返回 'https://' 时,此前两入口均接受并下发——现均省略字段
292
+ const serverCtx = buildServer();
293
+ serverCtx.services.register(INDOOR_NAVIGATION_SERVICE, { resolveJumpUrl: async () => 'https://' });
294
+ const tool = await runGetShopTool(serverCtx, 'mall-1');
295
+ expect(shopDetailCardDataSchema.parse(tool.cards![0]!.data).indoorNavigation).toBeUndefined();
296
+ const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
297
+ const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
298
+ expect(res.status).toBe(200);
299
+ expect(shopDetailCardDataSchema.parse(res.body.data).indoorNavigation).toBeUndefined();
300
+ });
301
+ });