@tbox.cn/app-module-shopping-guide 1.0.0-alpha.16 → 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.
- package/dist/{chunk-7FQ2WYWY.js → chunk-B3SVEGHZ.js} +21 -3
- package/dist/index.js +1 -1
- package/dist/server/index.d.ts +449 -448
- package/dist/server/index.js +1 -1
- package/package.json +6 -6
- package/skills/shopping-guide/SKILL.md +5 -0
- package/src/server/tools/index.ts +25 -3
- package/tests/shopping-guide.test.ts +34 -2
package/dist/server/index.js
CHANGED
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.
|
|
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-
|
|
23
|
-
"@tbox.cn/app-
|
|
24
|
-
"@tbox.cn/app-contracts
|
|
25
|
-
"@tbox.cn/app-agent-sdk-
|
|
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.
|
|
31
|
+
"@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.17"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/react": "18.3.31",
|
|
@@ -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 本轮失效),须本轮重查。
|
|
@@ -207,12 +207,14 @@ const CATEGORY_SYNONYMS: Readonly<Record<string, readonly string[]>> = {
|
|
|
207
207
|
* shopList 精简版:只含总数 + 每个门店的关键信息(名称/位置/类目/营业状态/优惠/电话),
|
|
208
208
|
* 不含 logo/cover/actions 等前端展示字段——减少模型上下文占用(200 条全量 card data 约 80KB+,精简版约 20KB)。 */
|
|
209
209
|
const summaries = {
|
|
210
|
-
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 => {
|
|
211
211
|
return JSON.stringify({
|
|
212
212
|
total: d.pageInfo?.total ?? d.items.length,
|
|
213
213
|
context: d.context,
|
|
214
|
+
...(nextPage ? { nextPage } : {}),
|
|
214
215
|
...(d.summary ? { summary: d.summary } : {}),
|
|
215
216
|
shops: (allItems ?? []).map((s) => ({
|
|
217
|
+
merchantId: s.merchantId,
|
|
216
218
|
name: s.name,
|
|
217
219
|
...(s.brand ? { brand: s.brand } : {}),
|
|
218
220
|
location: s.location?.displayText ?? s.location?.unitName,
|
|
@@ -300,7 +302,8 @@ export function createShoppingGuideTools(opts: {
|
|
|
300
302
|
id: 'search-shops',
|
|
301
303
|
description:
|
|
302
304
|
'门店搜索/列表:按品牌词、类目、楼层、楼栋搜索或浏览门店。输出 shop-list(卡片自带类目 Tab)。\n' +
|
|
303
|
-
'
|
|
305
|
+
'追问换一批时保留原筛选,传 excludedMerchantIds 排除已推荐店;不要执行下述首次搜索降级。\n' +
|
|
306
|
+
'【零参数 = 首次探索性全量浏览】以下意图必须不传任何参数直接调用本工具:\n' +
|
|
304
307
|
' "逛什么" / "有什么好逛的" / "随便逛逛" / "今天想逛逛" / "商场有什么" / "有哪些门店" / "有什么可逛的" / "帮我找找门店" / "看看有什么"\n' +
|
|
305
308
|
' → 返回全量门店列表,卡片自带类目 Tab,用户可在卡片上自行筛选,无需先列类目再追问。\n' +
|
|
306
309
|
'结果已含门店名、品类、楼栋/楼层/铺位、营业状态、促销信息,无需再调 get-shop 补位置。\n' +
|
|
@@ -343,6 +346,8 @@ export function createShoppingGuideTools(opts: {
|
|
|
343
346
|
businessCategory: optionalStr('类目编码(来自 pre-tool 上下文 categories[].code);按类目浏览时填写'),
|
|
344
347
|
floorCode: optionalStr('楼层 ID(来自 pre-tool 上下文 floors[].id);按楼层筛选时填写'),
|
|
345
348
|
buildingCode: optionalStr('楼栋 ID(来自 pre-tool 上下文 blocks[].id);按楼栋筛选时填写'),
|
|
349
|
+
excludedMerchantIds: coerce(z.array(z.string().min(1))).optional()
|
|
350
|
+
.describe('换一批时传已推荐门店的 merchantId,沿用楼层、楼栋、类目与关键词'),
|
|
346
351
|
...pageFields,
|
|
347
352
|
}),
|
|
348
353
|
execute: exec(async (ports, _ctx, args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
@@ -367,7 +372,24 @@ export function createShoppingGuideTools(opts: {
|
|
|
367
372
|
pageSize,
|
|
368
373
|
};
|
|
369
374
|
console.warn(`[search-shops] input keywords=${JSON.stringify(criteria.keywords)} businessCategory=${args.businessCategory ?? ''} floorCode=${args.floorCode ?? ''} buildingCode=${args.buildingCode ?? ''} page=${page}`);
|
|
370
|
-
|
|
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
|
+
}
|
|
371
393
|
console.warn(`[search-shops] output total=${result.total} items=${result.items.length} first=${result.items[0]?.name ?? '(empty)'}`);
|
|
372
394
|
const data = buildShopListCard(result, q, !hasFilter);
|
|
373
395
|
if (data.items.length === 0) return { summary: summaries.shopList(data) }; // 空结果不出卡
|
|
@@ -86,7 +86,7 @@ const portOf = (bag: Record<string, unknown>, service: string): unknown =>
|
|
|
86
86
|
const FIXTURE_PROVIDER = 'fixture';
|
|
87
87
|
const FIXTURE_PROVIDER_ID = 'fixture-shopping@1';
|
|
88
88
|
|
|
89
|
-
function buildFixtureServer(): ServerContext {
|
|
89
|
+
function buildFixtureServer(ports = stubShoppingPorts()): ServerContext {
|
|
90
90
|
const registry = createIntegrationsRegistry({
|
|
91
91
|
integrations: {
|
|
92
92
|
services: {
|
|
@@ -111,7 +111,7 @@ function buildFixtureServer(): ServerContext {
|
|
|
111
111
|
instanceIdOf: (scope) => scope.mallId ?? '',
|
|
112
112
|
});
|
|
113
113
|
registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) =>
|
|
114
|
-
portOf(
|
|
114
|
+
portOf(ports as unknown as Record<string, unknown>, input.service));
|
|
115
115
|
|
|
116
116
|
const serverCtx = createServerContext({
|
|
117
117
|
state: createInMemoryStateStore(),
|
|
@@ -146,6 +146,38 @@ describe('S2 读链端到端(stub 槽位产物 → 投影 → 工具)', () =
|
|
|
146
146
|
expect(result.cards[0].note).toBe('示例运动店(3 楼)');
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
+
it('换一批排除已推荐门店,空批既不出卡也不向正文泄露旧店', async () => {
|
|
150
|
+
const server = buildFixtureServer();
|
|
151
|
+
const tools = createShoppingGuideTools({ getCtx: () => server });
|
|
152
|
+
const result = await tools.searchShops.execute!(
|
|
153
|
+
{ floorCode: 'F3', excludedMerchantIds: ['shop:1'] } as never,
|
|
154
|
+
createToolExecContext(ctx()) as never,
|
|
155
|
+
) as { summary: string; cards?: unknown[] };
|
|
156
|
+
expect(result.cards).toBeUndefined();
|
|
157
|
+
expect(JSON.parse(result.summary)).toMatchObject({ shops: [], total: 0 });
|
|
158
|
+
expect(result.summary).not.toContain('示例运动店');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('旧店占满一页时沿用筛选翻页,正文与卡片同批排除', async () => {
|
|
162
|
+
const ports = stubShoppingPorts();
|
|
163
|
+
const query = ports.shop.searchShops.bind(ports.shop);
|
|
164
|
+
ports.shop.searchShops = vi.fn(async (criteria) => {
|
|
165
|
+
const page = await query(criteria);
|
|
166
|
+
return criteria.page === 1 ? { ...page, total: 2, hasMore: true } : {
|
|
167
|
+
...page, page: 2, items: page.items.map((s) => ({ ...s, merchantId: 'shop:2', name: '另一家店' })),
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
const server = buildFixtureServer(ports);
|
|
171
|
+
const tools = createShoppingGuideTools({ getCtx: () => server });
|
|
172
|
+
const result = await tools.searchShops.execute!(
|
|
173
|
+
{ floorCode: 'F3', businessCategory: '运动', excludedMerchantIds: ['shop:1'] } as never,
|
|
174
|
+
createToolExecContext(ctx()) as never,
|
|
175
|
+
) as { summary: string; cards: { data: { items: { merchantId: string }[] } }[] };
|
|
176
|
+
expect(ports.shop.searchShops).toHaveBeenNthCalledWith(2, expect.objectContaining({ page: 2, floorCode: 'F3', businessCategory: '运动' }));
|
|
177
|
+
expect(result.cards[0].data.items.map((s) => s.merchantId)).toEqual(['shop:2']);
|
|
178
|
+
expect(JSON.parse(result.summary).shops.map((s: { merchantId: string }) => s.merchantId)).toEqual(['shop:2']);
|
|
179
|
+
});
|
|
180
|
+
|
|
149
181
|
it.skip('compare-products:暂停——provider 无商品接口', async () => {
|
|
150
182
|
// 工具已暂停注册,用例保留备用
|
|
151
183
|
});
|