@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.
- package/LICENSE +21 -0
- package/dist/chunk-AGBLC6XI.js +1294 -0
- package/dist/chunk-U4WDS5PQ.js +173 -0
- package/dist/client/index.d.ts +25 -0
- package/dist/client/index.js +6 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +22 -0
- package/dist/server/index.d.ts +4098 -0
- package/dist/server/index.js +18 -0
- package/package.json +62 -0
- package/skills/shopping-guide/SKILL.md +36 -0
- package/skills/shopping-guide/references/comparison-format.md +5 -0
- package/skills/shopping-guide/references/faq-answers.md +5 -0
- package/skills/shopping-guide/references/floor-directory.md +4 -0
- package/skills/shopping-guide/references/intent-patterns.md +5 -0
- package/skills/shopping-guide/references/location-format.md +5 -0
- package/skills/shopping-guide/references/policy-lookup.md +5 -0
- package/skills/shopping-guide/references/product-search-tips.md +6 -0
- package/skills/shopping-guide/references/recommendation-style.md +5 -0
- package/src/client/cards/index.tsx +267 -0
- package/src/client/index.ts +39 -0
- package/src/index.ts +6 -0
- package/src/server/cards/category-list/meta.ts +19 -0
- package/src/server/cards/customer-service-faq/meta.ts +18 -0
- package/src/server/cards/human-guide-list/meta.ts +19 -0
- package/src/server/cards/index.ts +43 -0
- package/src/server/cards/location-handoff/meta.ts +20 -0
- package/src/server/cards/mall-directory/meta.ts +27 -0
- package/src/server/cards/merchant-detail/meta.ts +27 -0
- package/src/server/cards/merchant-list/meta.ts +31 -0
- package/src/server/cards/nearby-mall-list/meta.ts +17 -0
- package/src/server/cards/product-comparison/meta.ts +29 -0
- package/src/server/cards/product-detail/meta.ts +29 -0
- package/src/server/cards/product-list/meta.ts +32 -0
- package/src/server/domain/value-objects.ts +49 -0
- package/src/server/index.ts +180 -0
- package/src/server/integrations/joycity/adapter.ts +226 -0
- package/src/server/integrations/joycity/auth-strategy.ts +38 -0
- package/src/server/integrations/joycity/gateway.ts +128 -0
- package/src/server/ports/index.ts +151 -0
- package/src/server/ports/local-adapters.ts +90 -0
- package/src/server/projections/index.ts +253 -0
- package/src/server/tools/index.ts +407 -0
- package/tbox.component.json +48 -0
- package/tests/shopping-guide.test.ts +290 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +29 -0
|
@@ -0,0 +1,1294 @@
|
|
|
1
|
+
// src/server/index.ts
|
|
2
|
+
import { definePreTool, loadModuleSkills } from "@tbox.cn/app-sdk/server";
|
|
3
|
+
|
|
4
|
+
// src/server/cards/product-list/meta.ts
|
|
5
|
+
import { productListCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
6
|
+
|
|
7
|
+
// src/server/domain/value-objects.ts
|
|
8
|
+
import { parseMallScope } from "@tbox.cn/app-contracts-mall";
|
|
9
|
+
function toShoppingQueryContext(requestContext, subjectId) {
|
|
10
|
+
const scope = parseMallScope(requestContext.attributes);
|
|
11
|
+
if (!scope) {
|
|
12
|
+
throw new Error("\u7F3A\u5C11 mall scope\uFF08\u5DE5\u5177\u9700\u5728 mall \u4F1A\u8BDD\u5185\u8C03\u7528\uFF09");
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
scope,
|
|
16
|
+
...subjectId ? { subjectId } : {},
|
|
17
|
+
requestContext
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function nowIso() {
|
|
21
|
+
return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/server/cards/product-list/meta.ts
|
|
25
|
+
var meta = {
|
|
26
|
+
cardType: "product-list",
|
|
27
|
+
dataSchema: productListCardDataSchema,
|
|
28
|
+
allowedTools: ["recommend", "search-products", "list-browsing-history"],
|
|
29
|
+
displayName: "\u5546\u54C1\u5217\u8868",
|
|
30
|
+
description: "\u63A8\u8350/\u641C\u7D22/\u5386\u53F2\u5546\u54C1\u5217\u8868\uFF08\u542B\u4EF7\u683C\u3001\u5E93\u5B58\u3001\u95E8\u5E97\uFF09",
|
|
31
|
+
sampleData: {
|
|
32
|
+
context: "search",
|
|
33
|
+
items: [
|
|
34
|
+
{
|
|
35
|
+
productId: "p1",
|
|
36
|
+
name: "\u793A\u4F8B\u8DD1\u978B",
|
|
37
|
+
categoryPath: ["\u8FD0\u52A8", "\u8DD1\u6B65"],
|
|
38
|
+
price: { sale: { currency: "CNY", amountMinor: 39900, display: "\xA5399.00" } },
|
|
39
|
+
availability: { status: "in_stock", label: "\u6709\u8D27", marketable: true, observedAt: nowIso() },
|
|
40
|
+
merchant: { merchantId: "m1", name: "\u793A\u4F8B\u95E8\u5E97" },
|
|
41
|
+
badges: ["\u70ED\u5356"],
|
|
42
|
+
caveats: [],
|
|
43
|
+
itemActions: []
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
refinements: []
|
|
47
|
+
},
|
|
48
|
+
priority: 90,
|
|
49
|
+
schemaVersion: 1
|
|
50
|
+
};
|
|
51
|
+
var meta_default = meta;
|
|
52
|
+
|
|
53
|
+
// src/server/cards/product-detail/meta.ts
|
|
54
|
+
import { productDetailCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
55
|
+
var meta2 = {
|
|
56
|
+
cardType: "product-detail",
|
|
57
|
+
dataSchema: productDetailCardDataSchema,
|
|
58
|
+
allowedTools: ["get-product"],
|
|
59
|
+
displayName: "\u5546\u54C1\u8BE6\u60C5",
|
|
60
|
+
description: "\u5355\u4E2A\u5546\u54C1\u7684\u5B8C\u6574\u5FEB\u7167\uFF08\u4EF7\u683C/\u5E93\u5B58/\u5C5E\u6027/\u5546\u6237\uFF09",
|
|
61
|
+
sampleData: {
|
|
62
|
+
productId: "p1",
|
|
63
|
+
name: "\u793A\u4F8B\u8DD1\u978B",
|
|
64
|
+
imageUrls: [],
|
|
65
|
+
categoryPath: ["\u8FD0\u52A8"],
|
|
66
|
+
price: {},
|
|
67
|
+
availability: { status: "unknown", label: "\u672A\u77E5", marketable: false, observedAt: nowIso() },
|
|
68
|
+
merchant: { merchantId: "m1", name: "\u793A\u4F8B\u95E8\u5E97" },
|
|
69
|
+
attributes: [],
|
|
70
|
+
promotionFacts: [],
|
|
71
|
+
evidence: [],
|
|
72
|
+
humanGuideAvailable: false,
|
|
73
|
+
itemActions: []
|
|
74
|
+
},
|
|
75
|
+
priority: 80,
|
|
76
|
+
schemaVersion: 1
|
|
77
|
+
};
|
|
78
|
+
var meta_default2 = meta2;
|
|
79
|
+
|
|
80
|
+
// src/server/cards/merchant-list/meta.ts
|
|
81
|
+
import { merchantListCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
82
|
+
var meta3 = {
|
|
83
|
+
cardType: "merchant-list",
|
|
84
|
+
dataSchema: merchantListCardDataSchema,
|
|
85
|
+
allowedTools: ["search-merchants"],
|
|
86
|
+
displayName: "\u95E8\u5E97\u5217\u8868",
|
|
87
|
+
description: "\u63A8\u8350/\u641C\u7D22\u95E8\u5E97\u5217\u8868\uFF08\u542B\u4F4D\u7F6E\u3001\u8425\u4E1A\u72B6\u6001\u3001\u4FC3\u9500\uFF09",
|
|
88
|
+
sampleData: {
|
|
89
|
+
context: "search",
|
|
90
|
+
items: [
|
|
91
|
+
{
|
|
92
|
+
merchantId: "m1",
|
|
93
|
+
name: "\u793A\u4F8B\u95E8\u5E97",
|
|
94
|
+
businessCategories: ["\u9910\u996E"],
|
|
95
|
+
location: { displayText: "A \u680B 3 \u697C 301" },
|
|
96
|
+
status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: nowIso() },
|
|
97
|
+
services: ["\u5802\u98DF"],
|
|
98
|
+
promotionFacts: ["\u4F1A\u5458 9 \u6298"],
|
|
99
|
+
itemActions: []
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
refinements: []
|
|
103
|
+
},
|
|
104
|
+
priority: 90,
|
|
105
|
+
schemaVersion: 1
|
|
106
|
+
};
|
|
107
|
+
var meta_default3 = meta3;
|
|
108
|
+
|
|
109
|
+
// src/server/cards/merchant-detail/meta.ts
|
|
110
|
+
import { merchantDetailCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
111
|
+
var meta4 = {
|
|
112
|
+
cardType: "merchant-detail",
|
|
113
|
+
dataSchema: merchantDetailCardDataSchema,
|
|
114
|
+
allowedTools: ["get-merchant"],
|
|
115
|
+
displayName: "\u95E8\u5E97\u8BE6\u60C5",
|
|
116
|
+
description: "\u5355\u4E2A\u95E8\u5E97\u5B8C\u6574\u5FEB\u7167\uFF08\u56FE\u7247/\u7B80\u4ECB/\u8054\u7CFB\u65B9\u5F0F\uFF09",
|
|
117
|
+
sampleData: {
|
|
118
|
+
merchantId: "m1",
|
|
119
|
+
name: "\u793A\u4F8B\u95E8\u5E97",
|
|
120
|
+
coverUrls: [],
|
|
121
|
+
businessCategories: ["\u9910\u996E"],
|
|
122
|
+
location: { displayText: "A \u680B 3 \u697C" },
|
|
123
|
+
status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: nowIso() },
|
|
124
|
+
services: [],
|
|
125
|
+
promotionFacts: [],
|
|
126
|
+
evidence: [],
|
|
127
|
+
itemActions: []
|
|
128
|
+
},
|
|
129
|
+
priority: 80,
|
|
130
|
+
schemaVersion: 1
|
|
131
|
+
};
|
|
132
|
+
var meta_default4 = meta4;
|
|
133
|
+
|
|
134
|
+
// src/server/cards/category-list/meta.ts
|
|
135
|
+
import { categoryListCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
136
|
+
var meta5 = {
|
|
137
|
+
cardType: "category-list",
|
|
138
|
+
dataSchema: categoryListCardDataSchema,
|
|
139
|
+
allowedTools: ["list-categories"],
|
|
140
|
+
displayName: "\u4E1A\u6001\u5206\u7C7B\u76EE\u5F55",
|
|
141
|
+
description: "\u5546\u573A\u5168\u90E8\u4E1A\u6001\u5206\u7C7B\uFF08\u9910\u996E/\u96F6\u552E/\u5A31\u4E50\u7B49\uFF09",
|
|
142
|
+
sampleData: {
|
|
143
|
+
categories: [{ code: "c1", name: "\u9910\u996E", merchantCount: 42 }],
|
|
144
|
+
observedAt: nowIso()
|
|
145
|
+
},
|
|
146
|
+
priority: 100,
|
|
147
|
+
schemaVersion: 1
|
|
148
|
+
};
|
|
149
|
+
var meta_default5 = meta5;
|
|
150
|
+
|
|
151
|
+
// src/server/cards/product-comparison/meta.ts
|
|
152
|
+
import { productComparisonCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
153
|
+
var meta6 = {
|
|
154
|
+
cardType: "product-comparison",
|
|
155
|
+
dataSchema: productComparisonCardDataSchema,
|
|
156
|
+
allowedTools: ["compare-products"],
|
|
157
|
+
displayName: "\u5546\u54C1\u5BF9\u6BD4",
|
|
158
|
+
description: "2-4 \u4E2A\u5546\u54C1\u4EF7\u683C/\u5C5E\u6027/\u5E93\u5B58\u5E76\u6392\u5BF9\u6BD4",
|
|
159
|
+
sampleData: {
|
|
160
|
+
products: [
|
|
161
|
+
{
|
|
162
|
+
productId: "p1",
|
|
163
|
+
name: "\u5546\u54C1 A",
|
|
164
|
+
price: {},
|
|
165
|
+
availability: { status: "unknown", label: "\u672A\u77E5", marketable: false, observedAt: nowIso() },
|
|
166
|
+
merchant: { merchantId: "m1", name: "\u95E8\u5E97" },
|
|
167
|
+
attributes: [],
|
|
168
|
+
caveats: []
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
observedAt: nowIso()
|
|
172
|
+
},
|
|
173
|
+
priority: 120,
|
|
174
|
+
schemaVersion: 1
|
|
175
|
+
};
|
|
176
|
+
var meta_default6 = meta6;
|
|
177
|
+
|
|
178
|
+
// src/server/cards/mall-directory/meta.ts
|
|
179
|
+
import { mallDirectoryCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
180
|
+
var meta7 = {
|
|
181
|
+
cardType: "mall-directory",
|
|
182
|
+
dataSchema: mallDirectoryCardDataSchema,
|
|
183
|
+
allowedTools: ["mall-directory"],
|
|
184
|
+
displayName: "\u5546\u573A\u697C\u5C42\u76EE\u5F55",
|
|
185
|
+
description: "\u697C\u680B-\u697C\u5C42\u7ED3\u6784\uFF08\u51E0\u697C\u6709\u4EC0\u4E48\uFF09",
|
|
186
|
+
sampleData: {
|
|
187
|
+
mallId: "mall-1",
|
|
188
|
+
mallName: "\u793A\u4F8B\u5546\u573A",
|
|
189
|
+
buildings: [
|
|
190
|
+
{
|
|
191
|
+
buildingCode: "A",
|
|
192
|
+
buildingName: "A \u680B",
|
|
193
|
+
floors: [{ floorCode: "3F", floorName: "3 \u697C", businessCategories: ["\u9910\u996E"], merchantCount: 12 }]
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
observedAt: nowIso()
|
|
197
|
+
},
|
|
198
|
+
priority: 100,
|
|
199
|
+
schemaVersion: 1
|
|
200
|
+
};
|
|
201
|
+
var meta_default7 = meta7;
|
|
202
|
+
|
|
203
|
+
// src/server/cards/nearby-mall-list/meta.ts
|
|
204
|
+
import { nearbyMallListCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
205
|
+
var meta8 = {
|
|
206
|
+
cardType: "nearby-mall-list",
|
|
207
|
+
dataSchema: nearbyMallListCardDataSchema,
|
|
208
|
+
allowedTools: ["list-nearby-malls"],
|
|
209
|
+
displayName: "\u9644\u8FD1\u5546\u573A",
|
|
210
|
+
description: "\u9644\u8FD1\u53EF\u5207\u6362\u7684\u5927\u60A6\u57CE\u95E8\u5E97\u5217\u8868",
|
|
211
|
+
sampleData: {
|
|
212
|
+
malls: [{ mallId: "mall-1", name: "\u793A\u4F8B\u5546\u573A", address: "\u793A\u4F8B\u5730\u5740", status: { code: "open", label: "\u8425\u4E1A\u4E2D" }, itemActions: [] }]
|
|
213
|
+
},
|
|
214
|
+
priority: 100,
|
|
215
|
+
schemaVersion: 1
|
|
216
|
+
};
|
|
217
|
+
var meta_default8 = meta8;
|
|
218
|
+
|
|
219
|
+
// src/server/cards/customer-service-faq/meta.ts
|
|
220
|
+
import { customerServiceFaqCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
221
|
+
var meta9 = {
|
|
222
|
+
cardType: "customer-service-faq",
|
|
223
|
+
dataSchema: customerServiceFaqCardDataSchema,
|
|
224
|
+
allowedTools: ["customer-service-faq"],
|
|
225
|
+
displayName: "\u5BA2\u670DFAQ",
|
|
226
|
+
description: "\u5E38\u89C1\u95EE\u9898\u7B54\u6848\uFF08\u9000\u6362\u8D27/\u79EF\u5206/\u505C\u8F66\u653F\u7B56\uFF09",
|
|
227
|
+
sampleData: {
|
|
228
|
+
query: "\u5982\u4F55\u9000\u6362\u8D27",
|
|
229
|
+
faqs: [{ question: "\u5982\u4F55\u9000\u6362\u8D27", answer: "\u51ED\u5C0F\u7968 7 \u5929\u5185\u53EF\u9000\u6362\u3002", relevanceScore: 0.9 }]
|
|
230
|
+
},
|
|
231
|
+
priority: 100,
|
|
232
|
+
schemaVersion: 1
|
|
233
|
+
};
|
|
234
|
+
var meta_default9 = meta9;
|
|
235
|
+
|
|
236
|
+
// src/server/cards/human-guide-list/meta.ts
|
|
237
|
+
import { humanGuideListCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
238
|
+
var meta10 = {
|
|
239
|
+
cardType: "human-guide-list",
|
|
240
|
+
dataSchema: humanGuideListCardDataSchema,
|
|
241
|
+
allowedTools: ["list-human-guides"],
|
|
242
|
+
displayName: "\u4EBA\u5DE5\u5BFC\u8D2D",
|
|
243
|
+
description: "\u6307\u5B9A\u95E8\u5E97\u53EF\u8054\u7CFB\u7684\u5BFC\u8D2D\u5458\u5217\u8868",
|
|
244
|
+
sampleData: {
|
|
245
|
+
merchantId: "m1",
|
|
246
|
+
merchantName: "\u793A\u4F8B\u95E8\u5E97",
|
|
247
|
+
guides: [{ guideId: "g1", name: "\u5C0F\u5BFC", available: true, itemActions: [] }]
|
|
248
|
+
},
|
|
249
|
+
priority: 100,
|
|
250
|
+
schemaVersion: 1
|
|
251
|
+
};
|
|
252
|
+
var meta_default10 = meta10;
|
|
253
|
+
|
|
254
|
+
// src/server/cards/location-handoff/meta.ts
|
|
255
|
+
import { locationHandoffCardDataSchema } from "@tbox.cn/app-contracts-mall";
|
|
256
|
+
var meta11 = {
|
|
257
|
+
cardType: "location-handoff",
|
|
258
|
+
dataSchema: locationHandoffCardDataSchema,
|
|
259
|
+
allowedTools: ["get-location"],
|
|
260
|
+
displayName: "\u4F4D\u7F6E\u5BFC\u822A",
|
|
261
|
+
description: "\u95E8\u5E97\u4F4D\u7F6E\u4E0E\u5BFC\u822A\u80FD\u529B",
|
|
262
|
+
sampleData: {
|
|
263
|
+
merchantId: "m1",
|
|
264
|
+
merchantName: "\u793A\u4F8B\u95E8\u5E97",
|
|
265
|
+
location: { displayText: "A \u680B 3 \u697C 301" },
|
|
266
|
+
itemActions: []
|
|
267
|
+
},
|
|
268
|
+
priority: 110,
|
|
269
|
+
schemaVersion: 1
|
|
270
|
+
};
|
|
271
|
+
var meta_default11 = meta11;
|
|
272
|
+
|
|
273
|
+
// src/server/tools/index.ts
|
|
274
|
+
import { createTool, coerceStringifiedFields } from "@tbox.cn/app-sdk/server";
|
|
275
|
+
import { z } from "zod";
|
|
276
|
+
import { parseMallScope as parseMallScope3 } from "@tbox.cn/app-contracts-mall";
|
|
277
|
+
|
|
278
|
+
// src/server/ports/index.ts
|
|
279
|
+
import { createKnowledgeClient } from "@tbox.cn/app-sdk/server";
|
|
280
|
+
import { parseMallScope as parseMallScope2 } from "@tbox.cn/app-contracts-mall";
|
|
281
|
+
|
|
282
|
+
// src/server/integrations/joycity/adapter.ts
|
|
283
|
+
var JoyCityCatalogAdapter = class {
|
|
284
|
+
constructor(gateway) {
|
|
285
|
+
this.gateway = gateway;
|
|
286
|
+
}
|
|
287
|
+
gateway;
|
|
288
|
+
async searchProducts(criteria) {
|
|
289
|
+
const items = await this.gateway.searchProducts({
|
|
290
|
+
Keyword: criteria.keyword ?? "",
|
|
291
|
+
PageIndex: criteria.page,
|
|
292
|
+
PageSize: criteria.pageSize,
|
|
293
|
+
...criteria.categoryCode ? { CommercialTypeID: Number(criteria.categoryCode) } : {},
|
|
294
|
+
...criteria.minPriceMinor !== void 0 ? { MinPriceMinor: criteria.minPriceMinor } : {},
|
|
295
|
+
...criteria.maxPriceMinor !== void 0 ? { MaxPriceMinor: criteria.maxPriceMinor } : {}
|
|
296
|
+
});
|
|
297
|
+
const mapped = items.map((dto, order) => mapProductDto(dto, order));
|
|
298
|
+
return {
|
|
299
|
+
items: mapped,
|
|
300
|
+
page: criteria.page,
|
|
301
|
+
pageSize: criteria.pageSize,
|
|
302
|
+
total: mapped.length,
|
|
303
|
+
hasMore: mapped.length === criteria.pageSize
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
async getProduct(productId, _ctx) {
|
|
307
|
+
const dto = await this.gateway.getProduct({ ProductID: Number(productId) });
|
|
308
|
+
if (!dto) return null;
|
|
309
|
+
return mapProductDto(dto, 0);
|
|
310
|
+
}
|
|
311
|
+
async getFacets(_criteria) {
|
|
312
|
+
return { brands: [], categories: [], priceRanges: [], floors: [] };
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var JoyCityMerchantAdapter = class {
|
|
316
|
+
constructor(gateway) {
|
|
317
|
+
this.gateway = gateway;
|
|
318
|
+
}
|
|
319
|
+
gateway;
|
|
320
|
+
async searchMerchants(criteria) {
|
|
321
|
+
const items = await this.gateway.listMerchants({
|
|
322
|
+
Keyword: criteria.keyword ?? "",
|
|
323
|
+
PageIndex: criteria.page,
|
|
324
|
+
PageSize: criteria.pageSize,
|
|
325
|
+
...criteria.businessCategory ? { CommercialTypeID: Number(criteria.businessCategory) } : {},
|
|
326
|
+
...criteria.floorCode ? { FloorCode: criteria.floorCode } : {},
|
|
327
|
+
...criteria.buildingCode ? { BuildingCode: criteria.buildingCode } : {}
|
|
328
|
+
});
|
|
329
|
+
const mapped = items.map(mapMerchantListItem);
|
|
330
|
+
return {
|
|
331
|
+
items: mapped,
|
|
332
|
+
page: criteria.page,
|
|
333
|
+
pageSize: criteria.pageSize,
|
|
334
|
+
total: mapped.length,
|
|
335
|
+
hasMore: mapped.length === criteria.pageSize
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
async getMerchant(merchantId, _ctx) {
|
|
339
|
+
const dto = await this.gateway.getMerchant({ MerchantID: Number(merchantId) });
|
|
340
|
+
if (!dto) return null;
|
|
341
|
+
return {
|
|
342
|
+
...mapMerchantListItem(dto),
|
|
343
|
+
...dto.Description ? { description: dto.Description } : {},
|
|
344
|
+
...dto.ContactInfo?.length ? {
|
|
345
|
+
contactInfo: dto.ContactInfo.filter((c) => c.Channel && c.Value).map((c) => ({
|
|
346
|
+
channel: String(c.Channel),
|
|
347
|
+
value: String(c.Value)
|
|
348
|
+
}))
|
|
349
|
+
} : {}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var JoyCityCategoryAdapter = class {
|
|
354
|
+
constructor(gateway) {
|
|
355
|
+
this.gateway = gateway;
|
|
356
|
+
}
|
|
357
|
+
gateway;
|
|
358
|
+
async listCategories(_ctx) {
|
|
359
|
+
const categories = await this.gateway.listCategories({ Level: 1, PageIndex: 1, PageSize: 100 });
|
|
360
|
+
return categories.map((c) => ({
|
|
361
|
+
code: String(c.CategoryID ?? ""),
|
|
362
|
+
name: c.Name ?? "",
|
|
363
|
+
...c.Description ? { description: c.Description } : {},
|
|
364
|
+
merchantCount: c.MerchantCount ?? 0,
|
|
365
|
+
...c.SubCategories?.length ? {
|
|
366
|
+
subCategories: c.SubCategories.map((s) => ({
|
|
367
|
+
code: String(s.CategoryID ?? ""),
|
|
368
|
+
name: s.Name ?? "",
|
|
369
|
+
merchantCount: s.MerchantCount ?? 0
|
|
370
|
+
}))
|
|
371
|
+
} : {}
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
var JoyCityMallDirectoryAdapter = class {
|
|
376
|
+
constructor(gateway) {
|
|
377
|
+
this.gateway = gateway;
|
|
378
|
+
}
|
|
379
|
+
gateway;
|
|
380
|
+
async getDirectory(ctx) {
|
|
381
|
+
const dto = await this.gateway.getMallDirectory({ MallID: ctx.scope.mallId });
|
|
382
|
+
if (!dto) return null;
|
|
383
|
+
return {
|
|
384
|
+
mallId: dto.MallID ?? ctx.scope.mallId,
|
|
385
|
+
mallName: dto.MallName ?? ctx.scope.mallId,
|
|
386
|
+
buildings: (dto.Buildings ?? []).map((b) => ({
|
|
387
|
+
buildingCode: b.BuildingCode ?? "",
|
|
388
|
+
buildingName: b.BuildingName ?? "",
|
|
389
|
+
floors: (b.Floors ?? []).map((f) => ({
|
|
390
|
+
floorCode: f.FloorCode ?? "",
|
|
391
|
+
floorName: f.FloorName ?? "",
|
|
392
|
+
businessCategories: f.BusinessCategories ?? [],
|
|
393
|
+
merchantCount: f.MerchantCount ?? 0
|
|
394
|
+
}))
|
|
395
|
+
})),
|
|
396
|
+
observedAt: nowIso()
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
function mapProductDto(dto, _order) {
|
|
401
|
+
const observedAt = nowIso();
|
|
402
|
+
return {
|
|
403
|
+
productId: String(dto.ProductID ?? ""),
|
|
404
|
+
name: dto.Name ?? "",
|
|
405
|
+
...dto.Description ? { description: dto.Description } : {},
|
|
406
|
+
...dto.ImageUrl ? { imageUrls: [dto.ImageUrl] } : { imageUrls: [] },
|
|
407
|
+
...dto.BrandName ? { brand: dto.BrandName } : {},
|
|
408
|
+
categoryPath: dto.CategoryPath ?? [],
|
|
409
|
+
price: dto.PriceYuan !== void 0 ? {
|
|
410
|
+
sale: {
|
|
411
|
+
currency: "CNY",
|
|
412
|
+
amountMinor: Math.round(dto.PriceYuan * 100),
|
|
413
|
+
display: `\xA5${dto.PriceYuan.toFixed(2)}`
|
|
414
|
+
},
|
|
415
|
+
...dto.OriginalPriceYuan !== void 0 && dto.OriginalPriceYuan > dto.PriceYuan ? {
|
|
416
|
+
original: {
|
|
417
|
+
currency: "CNY",
|
|
418
|
+
amountMinor: Math.round(dto.OriginalPriceYuan * 100),
|
|
419
|
+
display: `\xA5${dto.OriginalPriceYuan.toFixed(2)}`
|
|
420
|
+
}
|
|
421
|
+
} : {}
|
|
422
|
+
} : {},
|
|
423
|
+
availability: {
|
|
424
|
+
status: dto.Marketable === false ? "out_of_stock" : "in_stock",
|
|
425
|
+
label: dto.StockLabel ?? "\u6709\u8D27",
|
|
426
|
+
marketable: dto.Marketable !== false,
|
|
427
|
+
observedAt
|
|
428
|
+
},
|
|
429
|
+
merchant: {
|
|
430
|
+
merchantId: String(dto.MerchantID ?? ""),
|
|
431
|
+
name: dto.MerchantName ?? "",
|
|
432
|
+
location: {
|
|
433
|
+
displayText: [dto.BuildingName, dto.FloorName, dto.UnitName].filter(Boolean).join(" ") || "\u4F4D\u7F6E\u5F85\u786E\u8BA4",
|
|
434
|
+
...dto.BuildingName ? { buildingName: dto.BuildingName } : {},
|
|
435
|
+
...dto.FloorName ? { floorName: dto.FloorName } : {},
|
|
436
|
+
...dto.UnitName ? { unitName: dto.UnitName } : {}
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
labels: dto.Labels ?? [],
|
|
440
|
+
attributes: [],
|
|
441
|
+
promotionFacts: dto.PromotionFacts ?? [],
|
|
442
|
+
observedAt
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function mapMerchantListItem(dto) {
|
|
446
|
+
const observedAt = nowIso();
|
|
447
|
+
return {
|
|
448
|
+
merchantId: String(dto.MerchantID ?? ""),
|
|
449
|
+
name: dto.Name ?? "",
|
|
450
|
+
...dto.LogoUrl ? { logoUrl: dto.LogoUrl } : {},
|
|
451
|
+
...dto.CoverUrl ? { coverUrls: [dto.CoverUrl] } : { coverUrls: [] },
|
|
452
|
+
...dto.BrandName ? { brand: dto.BrandName } : {},
|
|
453
|
+
businessCategories: [dto.CommercialTypeName].filter((x) => Boolean(x)),
|
|
454
|
+
location: {
|
|
455
|
+
displayText: [dto.BuildingName, dto.FloorName, dto.UnitName].filter(Boolean).join(" ") || "\u4F4D\u7F6E\u5F85\u786E\u8BA4",
|
|
456
|
+
...dto.BuildingName ? { buildingName: dto.BuildingName } : {},
|
|
457
|
+
...dto.FloorName ? { floorName: dto.FloorName } : {},
|
|
458
|
+
...dto.UnitName ? { unitName: dto.UnitName } : {}
|
|
459
|
+
},
|
|
460
|
+
status: {
|
|
461
|
+
code: dto.Status === 0 ? "disabled" : "enabled",
|
|
462
|
+
label: dto.Status === 0 ? "\u6682\u505C\u8425\u4E1A" : "\u8425\u4E1A\u4E2D",
|
|
463
|
+
observedAt
|
|
464
|
+
},
|
|
465
|
+
services: dto.Services ?? [],
|
|
466
|
+
promotionFacts: dto.PromotionFacts ?? [],
|
|
467
|
+
observedAt
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/server/integrations/joycity/gateway.ts
|
|
472
|
+
var JOYCITY_READ_OPERATIONS = {
|
|
473
|
+
listMerchants: "/api/merchant/list",
|
|
474
|
+
getMerchant: "/api/merchant/detail",
|
|
475
|
+
listCategories: "/api/category/list",
|
|
476
|
+
searchProducts: "/api/product/search",
|
|
477
|
+
getProduct: "/api/product/detail",
|
|
478
|
+
mallDirectory: "/api/mall/directory",
|
|
479
|
+
nearbyMalls: "/api/mall/nearby"
|
|
480
|
+
};
|
|
481
|
+
var JoyCityTransportGateway = class {
|
|
482
|
+
#transport;
|
|
483
|
+
constructor(transport) {
|
|
484
|
+
this.#transport = transport;
|
|
485
|
+
Object.freeze(this);
|
|
486
|
+
}
|
|
487
|
+
async listMerchants(body) {
|
|
488
|
+
return this.#post(JOYCITY_READ_OPERATIONS.listMerchants, body);
|
|
489
|
+
}
|
|
490
|
+
async getMerchant(body) {
|
|
491
|
+
return this.#post(JOYCITY_READ_OPERATIONS.getMerchant, body);
|
|
492
|
+
}
|
|
493
|
+
async listCategories(body) {
|
|
494
|
+
return this.#post(JOYCITY_READ_OPERATIONS.listCategories, body);
|
|
495
|
+
}
|
|
496
|
+
async searchProducts(body) {
|
|
497
|
+
return this.#post(JOYCITY_READ_OPERATIONS.searchProducts, body);
|
|
498
|
+
}
|
|
499
|
+
async getProduct(body) {
|
|
500
|
+
return this.#post(JOYCITY_READ_OPERATIONS.getProduct, body);
|
|
501
|
+
}
|
|
502
|
+
async getMallDirectory(body) {
|
|
503
|
+
return this.#post(JOYCITY_READ_OPERATIONS.mallDirectory, body);
|
|
504
|
+
}
|
|
505
|
+
async #post(path, body) {
|
|
506
|
+
const response = await this.#transport.request({ path, body });
|
|
507
|
+
if (response.Code !== 1) {
|
|
508
|
+
throw new Error(`JoyCity API \u9519\u8BEF\uFF1ACode=${response.Code}`);
|
|
509
|
+
}
|
|
510
|
+
return response.Data;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
// src/server/ports/local-adapters.ts
|
|
515
|
+
var KnowledgeAssistanceAdapter = class {
|
|
516
|
+
constructor(knowledge) {
|
|
517
|
+
this.knowledge = knowledge;
|
|
518
|
+
}
|
|
519
|
+
knowledge;
|
|
520
|
+
async searchFaq(_ctx, query, topK = 3) {
|
|
521
|
+
const results = await this.knowledge.search({ datasetId: "faq", query, topK });
|
|
522
|
+
return results.map((hit) => ({
|
|
523
|
+
question: query,
|
|
524
|
+
answer: summarize(hit.content),
|
|
525
|
+
...hit.originFileName ? { category: hit.originFileName } : {},
|
|
526
|
+
relevanceScore: hit.score
|
|
527
|
+
}));
|
|
528
|
+
}
|
|
529
|
+
async searchKnowledge(_ctx, query, topK = 3) {
|
|
530
|
+
const results = await this.knowledge.search({ datasetId: "mall-knowledge", query, topK });
|
|
531
|
+
return results.map((hit) => ({
|
|
532
|
+
content: hit.content,
|
|
533
|
+
score: hit.score,
|
|
534
|
+
...hit.originFileName ? { title: hit.originFileName } : {}
|
|
535
|
+
}));
|
|
536
|
+
}
|
|
537
|
+
async listHumanGuides(merchantId, _ctx) {
|
|
538
|
+
void merchantId;
|
|
539
|
+
return [];
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
var LocalNavigationAdapter = class {
|
|
543
|
+
async getLocation(_merchantId, _ctx) {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
async listNearbyMalls(_ctx, _query) {
|
|
547
|
+
return [];
|
|
548
|
+
}
|
|
549
|
+
async listBrowsingHistory(_ctx, _page, _pageSize) {
|
|
550
|
+
return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
function summarize(content) {
|
|
554
|
+
return content.replace(/^#+\s+/gm, "").replace(/\s+/g, " ").trim().slice(0, 320);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/server/ports/index.ts
|
|
558
|
+
var SHOPPING_GUIDE_PROVIDER_TEMPLATE_ID = "joycity-commercial@1";
|
|
559
|
+
var PORT_CACHE_TTL_MS = 30 * 60 * 1e3;
|
|
560
|
+
var portCache = /* @__PURE__ */ new Map();
|
|
561
|
+
async function resolveShoppingGuidePorts(ctx) {
|
|
562
|
+
const mallId = currentMallId(ctx) ?? "none";
|
|
563
|
+
const cached = portCache.get(mallId);
|
|
564
|
+
if (cached && Date.now() - cached.at < PORT_CACHE_TTL_MS) return cached.ports;
|
|
565
|
+
let gateway;
|
|
566
|
+
try {
|
|
567
|
+
const resolved = await ctx.providers.resolve({
|
|
568
|
+
templateId: SHOPPING_GUIDE_PROVIDER_TEMPLATE_ID,
|
|
569
|
+
scope: mallId !== "none" ? { mallId } : {}
|
|
570
|
+
});
|
|
571
|
+
gateway = new JoyCityTransportGateway(resolved.transport);
|
|
572
|
+
} catch {
|
|
573
|
+
gateway = void 0;
|
|
574
|
+
}
|
|
575
|
+
const ports = gateway ? {
|
|
576
|
+
catalog: new JoyCityCatalogAdapter(gateway),
|
|
577
|
+
merchant: new JoyCityMerchantAdapter(gateway),
|
|
578
|
+
category: new JoyCityCategoryAdapter(gateway),
|
|
579
|
+
directory: new JoyCityMallDirectoryAdapter(gateway),
|
|
580
|
+
assistance: createLocalAssistance(),
|
|
581
|
+
navigation: new LocalNavigationAdapter()
|
|
582
|
+
} : {
|
|
583
|
+
catalog: new EmptyCatalogAdapter(),
|
|
584
|
+
merchant: new EmptyMerchantAdapter(),
|
|
585
|
+
category: new EmptyCategoryAdapter(),
|
|
586
|
+
directory: new EmptyDirectoryAdapter(),
|
|
587
|
+
assistance: createLocalAssistance(),
|
|
588
|
+
navigation: new LocalNavigationAdapter()
|
|
589
|
+
};
|
|
590
|
+
portCache.set(mallId, { ports, at: Date.now() });
|
|
591
|
+
return ports;
|
|
592
|
+
}
|
|
593
|
+
var _localAssistance;
|
|
594
|
+
function createLocalAssistance() {
|
|
595
|
+
if (_localAssistance) return _localAssistance;
|
|
596
|
+
try {
|
|
597
|
+
_localAssistance = new KnowledgeAssistanceAdapter(createKnowledgeClient());
|
|
598
|
+
} catch {
|
|
599
|
+
_localAssistance = new EmptyAssistanceAdapter();
|
|
600
|
+
}
|
|
601
|
+
return _localAssistance;
|
|
602
|
+
}
|
|
603
|
+
function currentMallId(ctx) {
|
|
604
|
+
return parseMallScope2(ctx.auth.getContext()?.attributes)?.mallId;
|
|
605
|
+
}
|
|
606
|
+
var EmptyCatalogAdapter = class {
|
|
607
|
+
async searchProducts() {
|
|
608
|
+
return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
|
|
609
|
+
}
|
|
610
|
+
async getProduct() {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
async getFacets() {
|
|
614
|
+
return { brands: [], categories: [], priceRanges: [], floors: [] };
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
var EmptyMerchantAdapter = class {
|
|
618
|
+
async searchMerchants() {
|
|
619
|
+
return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
|
|
620
|
+
}
|
|
621
|
+
async getMerchant() {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
var EmptyCategoryAdapter = class {
|
|
626
|
+
async listCategories() {
|
|
627
|
+
return [];
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
var EmptyDirectoryAdapter = class {
|
|
631
|
+
async getDirectory() {
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
var EmptyAssistanceAdapter = class {
|
|
636
|
+
async searchFaq() {
|
|
637
|
+
return [];
|
|
638
|
+
}
|
|
639
|
+
async searchKnowledge() {
|
|
640
|
+
return [];
|
|
641
|
+
}
|
|
642
|
+
async listHumanGuides() {
|
|
643
|
+
return [];
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
// src/server/projections/index.ts
|
|
648
|
+
function projectProductList(context, page, summary, noResultsReason) {
|
|
649
|
+
return {
|
|
650
|
+
context,
|
|
651
|
+
...summary ? { summary } : {},
|
|
652
|
+
items: page.items.map((p) => ({
|
|
653
|
+
productId: p.productId,
|
|
654
|
+
name: p.name,
|
|
655
|
+
...p.imageUrls[0] ? { imageUrl: p.imageUrls[0] } : {},
|
|
656
|
+
...p.brand ? { brand: p.brand } : {},
|
|
657
|
+
categoryPath: [...p.categoryPath],
|
|
658
|
+
price: p.price,
|
|
659
|
+
availability: p.availability,
|
|
660
|
+
merchant: {
|
|
661
|
+
merchantId: p.merchant.merchantId,
|
|
662
|
+
name: p.merchant.name,
|
|
663
|
+
...p.merchant.location ? { location: p.merchant.location } : {}
|
|
664
|
+
},
|
|
665
|
+
badges: [...p.labels],
|
|
666
|
+
caveats: [],
|
|
667
|
+
itemActions: []
|
|
668
|
+
})),
|
|
669
|
+
...noResultsReason ? { noResultsReason } : {},
|
|
670
|
+
...page.items.length > 0 ? { pageInfo: { page: page.page, pageSize: page.pageSize, total: page.total, hasMore: page.hasMore } } : {},
|
|
671
|
+
refinements: []
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
function projectProductDetail(p) {
|
|
675
|
+
return {
|
|
676
|
+
productId: p.productId,
|
|
677
|
+
name: p.name,
|
|
678
|
+
...p.description ? { description: p.description } : {},
|
|
679
|
+
imageUrls: [...p.imageUrls],
|
|
680
|
+
...p.brand ? { brand: p.brand } : {},
|
|
681
|
+
categoryPath: [...p.categoryPath],
|
|
682
|
+
price: p.price,
|
|
683
|
+
availability: p.availability,
|
|
684
|
+
merchant: {
|
|
685
|
+
merchantId: p.merchant.merchantId,
|
|
686
|
+
name: p.merchant.name,
|
|
687
|
+
...p.merchant.location ? { location: p.merchant.location } : {}
|
|
688
|
+
},
|
|
689
|
+
attributes: [...p.attributes],
|
|
690
|
+
promotionFacts: [...p.promotionFacts],
|
|
691
|
+
evidence: [],
|
|
692
|
+
humanGuideAvailable: false,
|
|
693
|
+
itemActions: []
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function projectMerchantList(context, page, summary) {
|
|
697
|
+
return {
|
|
698
|
+
context,
|
|
699
|
+
...summary ? { summary } : {},
|
|
700
|
+
items: page.items.map((m) => ({
|
|
701
|
+
merchantId: m.merchantId,
|
|
702
|
+
name: m.name,
|
|
703
|
+
...m.logoUrl ? { logoUrl: m.logoUrl } : {},
|
|
704
|
+
...m.coverUrls[0] ? { coverUrl: m.coverUrls[0] } : {},
|
|
705
|
+
...m.brand ? { brand: m.brand } : {},
|
|
706
|
+
businessCategories: [...m.businessCategories],
|
|
707
|
+
location: m.location,
|
|
708
|
+
status: m.status,
|
|
709
|
+
services: [...m.services],
|
|
710
|
+
promotionFacts: [...m.promotionFacts],
|
|
711
|
+
itemActions: []
|
|
712
|
+
})),
|
|
713
|
+
...page.items.length > 0 ? { pageInfo: { page: page.page, pageSize: page.pageSize, total: page.total, hasMore: page.hasMore } } : {},
|
|
714
|
+
refinements: []
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
function projectMerchantDetail(m) {
|
|
718
|
+
return {
|
|
719
|
+
merchantId: m.merchantId,
|
|
720
|
+
name: m.name,
|
|
721
|
+
...m.logoUrl ? { logoUrl: m.logoUrl } : {},
|
|
722
|
+
coverUrls: [...m.coverUrls],
|
|
723
|
+
...m.brand ? { brand: m.brand } : {},
|
|
724
|
+
businessCategories: [...m.businessCategories],
|
|
725
|
+
location: m.location,
|
|
726
|
+
status: m.status,
|
|
727
|
+
...m.description ? { description: m.description } : {},
|
|
728
|
+
...m.contactInfo ? { contactInfo: [...m.contactInfo] } : {},
|
|
729
|
+
services: [...m.services],
|
|
730
|
+
promotionFacts: [...m.promotionFacts],
|
|
731
|
+
evidence: [],
|
|
732
|
+
itemActions: []
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function projectCategoryList(categories) {
|
|
736
|
+
return {
|
|
737
|
+
categories: categories.map((c) => ({
|
|
738
|
+
code: c.code,
|
|
739
|
+
name: c.name,
|
|
740
|
+
...c.description ? { description: c.description } : {},
|
|
741
|
+
merchantCount: c.merchantCount,
|
|
742
|
+
...c.subCategories ? { subCategories: [...c.subCategories] } : {}
|
|
743
|
+
})),
|
|
744
|
+
observedAt: nowIso()
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function projectProductComparison(products) {
|
|
748
|
+
return {
|
|
749
|
+
products: products.map((p) => ({
|
|
750
|
+
productId: p.productId,
|
|
751
|
+
name: p.name,
|
|
752
|
+
...p.imageUrls[0] ? { imageUrl: p.imageUrls[0] } : {},
|
|
753
|
+
...p.brand ? { brand: p.brand } : {},
|
|
754
|
+
price: p.price,
|
|
755
|
+
availability: p.availability,
|
|
756
|
+
merchant: { merchantId: p.merchant.merchantId, name: p.merchant.name },
|
|
757
|
+
attributes: [...p.attributes],
|
|
758
|
+
caveats: []
|
|
759
|
+
})),
|
|
760
|
+
observedAt: nowIso()
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
function projectMallDirectory(d) {
|
|
764
|
+
return {
|
|
765
|
+
mallId: d.mallId,
|
|
766
|
+
mallName: d.mallName,
|
|
767
|
+
buildings: d.buildings.map((b) => ({
|
|
768
|
+
buildingCode: b.buildingCode,
|
|
769
|
+
buildingName: b.buildingName,
|
|
770
|
+
floors: b.floors.map((f) => ({
|
|
771
|
+
floorCode: f.floorCode,
|
|
772
|
+
floorName: f.floorName,
|
|
773
|
+
businessCategories: [...f.businessCategories],
|
|
774
|
+
merchantCount: f.merchantCount
|
|
775
|
+
}))
|
|
776
|
+
})),
|
|
777
|
+
observedAt: d.observedAt
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
function projectNearbyMalls(malls, query) {
|
|
781
|
+
return {
|
|
782
|
+
...query ? { query } : {},
|
|
783
|
+
malls: malls.map((m) => ({
|
|
784
|
+
mallId: m.mallId,
|
|
785
|
+
name: m.name,
|
|
786
|
+
address: m.address,
|
|
787
|
+
...m.distanceKm !== void 0 ? { distanceKm: m.distanceKm } : {},
|
|
788
|
+
status: m.status,
|
|
789
|
+
itemActions: []
|
|
790
|
+
}))
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
function projectCustomerServiceFaq(query, faqs, noResultsReason) {
|
|
794
|
+
return {
|
|
795
|
+
query,
|
|
796
|
+
faqs: faqs.map((f) => ({
|
|
797
|
+
question: f.question,
|
|
798
|
+
answer: f.answer,
|
|
799
|
+
...f.category ? { category: f.category } : {},
|
|
800
|
+
relevanceScore: f.relevanceScore
|
|
801
|
+
})),
|
|
802
|
+
...noResultsReason ? { noResultsReason } : {}
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
function projectHumanGuideList(merchantId, merchantName, guides) {
|
|
806
|
+
return {
|
|
807
|
+
merchantId,
|
|
808
|
+
merchantName,
|
|
809
|
+
guides: guides.map((g) => ({
|
|
810
|
+
guideId: g.guideId,
|
|
811
|
+
name: g.name,
|
|
812
|
+
...g.title ? { title: g.title } : {},
|
|
813
|
+
...g.avatarUrl ? { avatarUrl: g.avatarUrl } : {},
|
|
814
|
+
...g.contactInfo ? { contactInfo: [...g.contactInfo] } : {},
|
|
815
|
+
available: g.available,
|
|
816
|
+
itemActions: []
|
|
817
|
+
}))
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function projectLocationHandoff(merchant) {
|
|
821
|
+
return {
|
|
822
|
+
merchantId: merchant.merchantId,
|
|
823
|
+
merchantName: merchant.name,
|
|
824
|
+
location: merchant.location,
|
|
825
|
+
itemActions: []
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function projectKnowledge(knowledge) {
|
|
829
|
+
if (knowledge.length === 0) return "\u672A\u68C0\u7D22\u5230\u76F8\u5173\u77E5\u8BC6\u5185\u5BB9\u3002";
|
|
830
|
+
return knowledge.map((k) => `${k.title ? `\u3010${k.title}\u3011` : ""}${k.content}`.slice(0, 500)).join("\n\n");
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// src/server/tools/index.ts
|
|
834
|
+
var str = (desc) => z.string().describe(desc);
|
|
835
|
+
var optionalStr = (desc) => z.string().optional().describe(desc);
|
|
836
|
+
function coerce(schema) {
|
|
837
|
+
return z.preprocess(coerceStringifiedFields, schema);
|
|
838
|
+
}
|
|
839
|
+
function toContext(ctx) {
|
|
840
|
+
const requestContext = ctx.auth.getContext();
|
|
841
|
+
if (!requestContext) {
|
|
842
|
+
throw new Error("\u8FD0\u884C\u4E0A\u4E0B\u6587\u672A\u7ED1\u5B9A\uFF08\u5DE5\u5177\u9700\u5728\u5BF9\u8BDD run \u7A97\u53E3\u5185\u8C03\u7528\uFF09");
|
|
843
|
+
}
|
|
844
|
+
const subjectId = requestContext.identity?.source === "local" || requestContext.identity?.source === "external" ? requestContext.identity.userId : void 0;
|
|
845
|
+
return toShoppingQueryContext(requestContext, subjectId);
|
|
846
|
+
}
|
|
847
|
+
function toLooseContext(ctx) {
|
|
848
|
+
const requestContext = ctx.auth.getContext();
|
|
849
|
+
if (!requestContext) {
|
|
850
|
+
throw new Error("\u8FD0\u884C\u4E0A\u4E0B\u6587\u672A\u7ED1\u5B9A\uFF08\u5DE5\u5177\u9700\u5728\u5BF9\u8BDD run \u7A97\u53E3\u5185\u8C03\u7528\uFF09");
|
|
851
|
+
}
|
|
852
|
+
const scope = parseMallScope3(requestContext.attributes) ?? { miniAppId: "", mallId: "" };
|
|
853
|
+
return {
|
|
854
|
+
scope,
|
|
855
|
+
requestContext
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
var pageFields = {
|
|
859
|
+
page: z.string().optional().describe("\u9875\u7801\uFF08\u4ECE 1 \u5F00\u59CB\uFF0C\u5B57\u7B26\u4E32\uFF09"),
|
|
860
|
+
pageSize: z.string().optional().describe("\u6BCF\u9875\u6761\u6570\uFF08\u5B57\u7B26\u4E32\uFF0C\u7F3A\u7701 10\uFF09")
|
|
861
|
+
};
|
|
862
|
+
function parsePage(page, pageSize) {
|
|
863
|
+
const p = Math.max(1, Number(page) || 1);
|
|
864
|
+
const s = Math.min(50, Math.max(1, Number(pageSize) || 10));
|
|
865
|
+
return { page: p, pageSize: s };
|
|
866
|
+
}
|
|
867
|
+
function createShoppingGuideTools(opts) {
|
|
868
|
+
const portsOf = () => resolveShoppingGuidePorts(opts.getCtx());
|
|
869
|
+
const exec = (fn) => {
|
|
870
|
+
return async (args) => {
|
|
871
|
+
const ctx = opts.getCtx();
|
|
872
|
+
return fn(await portsOf(), ctx, args);
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
const recommend = createTool({
|
|
876
|
+
id: "recommend",
|
|
877
|
+
description: "\u667A\u80FD\u63A8\u8350\uFF1A\u4ECE\u6743\u5A01\u5546\u54C1\u6570\u636E\u4E2D\u6311\u9009\u6700\u7B26\u5408\u7528\u6237\u9700\u6C42\u7684\u7ED3\u679C\u3002\u8F93\u51FA product-list(context=recommendation)\u3002\u5546\u6237\u63A8\u8350\u8BF7\u7528 search-merchants\u3002",
|
|
878
|
+
inputSchema: z.object({
|
|
879
|
+
query: str("\u7528\u6237\u8D2D\u7269\u9700\u6C42\u7684\u81EA\u7136\u8BED\u8A00\u63CF\u8FF0")
|
|
880
|
+
}),
|
|
881
|
+
execute: exec(async (ports, ctx, args) => {
|
|
882
|
+
const q = toContext(ctx);
|
|
883
|
+
const criteria = {
|
|
884
|
+
ctx: q,
|
|
885
|
+
keyword: String(args.query ?? ""),
|
|
886
|
+
page: 1,
|
|
887
|
+
pageSize: 10,
|
|
888
|
+
marketableOnly: true
|
|
889
|
+
};
|
|
890
|
+
const products = await ports.catalog.searchProducts(criteria);
|
|
891
|
+
return projectProductList("recommendation", products);
|
|
892
|
+
})
|
|
893
|
+
});
|
|
894
|
+
const searchProducts = createTool({
|
|
895
|
+
id: "search-products",
|
|
896
|
+
description: "\u5546\u54C1\u641C\u7D22\uFF1A\u6309\u5173\u952E\u8BCD/\u4EF7\u683C/\u54C1\u7C7B\u641C\u7D22\u5546\u54C1\u5217\u8868\u3002\u8F93\u51FA product-list(context=search)\u3002",
|
|
897
|
+
inputSchema: z.object({
|
|
898
|
+
keywords: coerce(z.array(z.string()).min(1).max(5).describe('\u5168\u90E8\u641C\u7D22\u89D2\u5EA6\uFF0C\u5982 ["\u8DD1\u978B","\u8FD0\u52A8\u978B"]')),
|
|
899
|
+
minPriceMinor: optionalStr("\u6700\u4F4E\u4EF7\u683C\uFF08\u5206\uFF0C\u5B57\u7B26\u4E32\uFF09"),
|
|
900
|
+
maxPriceMinor: optionalStr("\u6700\u9AD8\u4EF7\u683C\uFF08\u5206\uFF0C\u5B57\u7B26\u4E32\uFF09"),
|
|
901
|
+
categoryCode: optionalStr("\u54C1\u7C7B\u7F16\u7801"),
|
|
902
|
+
brandCode: optionalStr("\u54C1\u724C\u7F16\u7801"),
|
|
903
|
+
...pageFields
|
|
904
|
+
}),
|
|
905
|
+
execute: exec(async (ports, ctx, args) => {
|
|
906
|
+
const q = toContext(ctx);
|
|
907
|
+
const { page, pageSize } = parsePage(args.page, args.pageSize);
|
|
908
|
+
const result = await ports.catalog.searchProducts({
|
|
909
|
+
ctx: q,
|
|
910
|
+
keyword: args.keywords?.join(" ") ?? "",
|
|
911
|
+
keywords: args.keywords,
|
|
912
|
+
...args.minPriceMinor ? { minPriceMinor: Number(args.minPriceMinor) } : {},
|
|
913
|
+
...args.maxPriceMinor ? { maxPriceMinor: Number(args.maxPriceMinor) } : {},
|
|
914
|
+
...args.categoryCode ? { categoryCode: String(args.categoryCode) } : {},
|
|
915
|
+
...args.brandCode ? { brandCode: String(args.brandCode) } : {},
|
|
916
|
+
page,
|
|
917
|
+
pageSize,
|
|
918
|
+
marketableOnly: true
|
|
919
|
+
});
|
|
920
|
+
return projectProductList(
|
|
921
|
+
"search",
|
|
922
|
+
result,
|
|
923
|
+
void 0,
|
|
924
|
+
result.items.length === 0 ? "\u672A\u627E\u5230\u5339\u914D\u7684\u5546\u54C1\uFF0C\u53EF\u5C1D\u8BD5\u653E\u5BBD\u5173\u952E\u8BCD\u6216\u6362\u54C1\u7C7B\u3002" : void 0
|
|
925
|
+
);
|
|
926
|
+
})
|
|
927
|
+
});
|
|
928
|
+
const productFacets = createTool({
|
|
929
|
+
id: "product-facets",
|
|
930
|
+
description: "\u5546\u54C1\u5206\u9762\uFF1A\u67E5\u8BE2\u5F53\u524D\u54C1\u7C7B/\u5173\u952E\u8BCD\u4E0B\u53EF\u7528\u7684\u7B5B\u9009\u9879\uFF08\u4EF7\u683C\u533A\u95F4\u3001\u54C1\u724C\u3001\u54C1\u7C7B\u6811\uFF09\u3002",
|
|
931
|
+
inputSchema: z.object({
|
|
932
|
+
keyword: optionalStr("\u5173\u952E\u8BCD"),
|
|
933
|
+
minPriceMinor: optionalStr("\u6700\u4F4E\u4EF7\u683C\uFF08\u5206\uFF0C\u5B57\u7B26\u4E32\uFF09"),
|
|
934
|
+
maxPriceMinor: optionalStr("\u6700\u9AD8\u4EF7\u683C\uFF08\u5206\uFF0C\u5B57\u7B26\u4E32\uFF09")
|
|
935
|
+
}),
|
|
936
|
+
execute: exec(async (ports, ctx, args) => {
|
|
937
|
+
const q = toContext(ctx);
|
|
938
|
+
const facets = await ports.catalog.getFacets({
|
|
939
|
+
ctx: q,
|
|
940
|
+
...args.keyword ? { keyword: String(args.keyword) } : {},
|
|
941
|
+
...args.minPriceMinor ? { minPriceMinor: Number(args.minPriceMinor) } : {},
|
|
942
|
+
...args.maxPriceMinor ? { maxPriceMinor: Number(args.maxPriceMinor) } : {},
|
|
943
|
+
page: 1,
|
|
944
|
+
pageSize: 10
|
|
945
|
+
});
|
|
946
|
+
return facets;
|
|
947
|
+
})
|
|
948
|
+
});
|
|
949
|
+
const getProduct = createTool({
|
|
950
|
+
id: "get-product",
|
|
951
|
+
description: "\u5546\u54C1\u8BE6\u60C5\uFF1A\u52A0\u8F7D\u5355\u4E2A\u5546\u54C1\u7684\u5B8C\u6574\u5FEB\u7167\uFF08\u4EF7\u683C/\u5E93\u5B58/\u5C5E\u6027/\u5546\u6237\u5F52\u5C5E\uFF09\u3002\u8F93\u51FA product-detail\u3002",
|
|
952
|
+
inputSchema: z.object({ productId: str("\u5546\u54C1 ID\uFF08\u6765\u81EA\u641C\u7D22\u7ED3\u679C\u5361\uFF09") }),
|
|
953
|
+
execute: exec(async (ports, ctx, args) => {
|
|
954
|
+
const product = await ports.catalog.getProduct(String(args.productId), toContext(ctx));
|
|
955
|
+
if (!product) {
|
|
956
|
+
return { error: "\u672A\u627E\u5230\u8BE5\u5546\u54C1\uFF0C\u53EF\u80FD\u5DF2\u4E0B\u67B6\u3002" };
|
|
957
|
+
}
|
|
958
|
+
return projectProductDetail(product);
|
|
959
|
+
})
|
|
960
|
+
});
|
|
961
|
+
const compareProducts = createTool({
|
|
962
|
+
id: "compare-products",
|
|
963
|
+
description: "\u5546\u54C1\u5BF9\u6BD4\uFF1A\u5E76\u6392\u5BF9\u6BD4 2-4 \u4E2A\u5546\u54C1\u7684\u4EF7\u683C\u3001\u5C5E\u6027\u3001\u5E93\u5B58\u3002\u8F93\u51FA product-comparison\u3002",
|
|
964
|
+
inputSchema: z.object({
|
|
965
|
+
productIds: coerce(z.array(z.string()).min(2).max(4).describe("\u5F85\u5BF9\u6BD4\u7684\u5546\u54C1 ID \u6570\u7EC4"))
|
|
966
|
+
}),
|
|
967
|
+
execute: exec(async (ports, ctx, args) => {
|
|
968
|
+
const ids = args.productIds.slice(0, 4);
|
|
969
|
+
const q = toContext(ctx);
|
|
970
|
+
const products = (await Promise.all(ids.map((id) => ports.catalog.getProduct(id, q)))).filter(
|
|
971
|
+
(p) => p !== null
|
|
972
|
+
);
|
|
973
|
+
return projectProductComparison(products);
|
|
974
|
+
})
|
|
975
|
+
});
|
|
976
|
+
const searchMerchants = createTool({
|
|
977
|
+
id: "search-merchants",
|
|
978
|
+
description: "\u95E8\u5E97\u641C\u7D22\uFF1A\u6309\u5173\u952E\u8BCD/\u697C\u5C42/\u54C1\u7C7B\u641C\u7D22\u95E8\u5E97\u3002\u7ED3\u679C\u5DF2\u542B\u95E8\u5E97\u540D\u3001\u54C1\u7C7B\u3001\u697C\u680B/\u697C\u5C42/\u94FA\u4F4D\u3001\u8425\u4E1A\u72B6\u6001\u3001\u4FC3\u9500\u4FE1\u606F\uFF0C\u65E0\u9700\u5728\u540C\u4E00\u8F6E\u518D\u8C03 get-merchant \u8865\u4F4D\u7F6E\u3002\u8F93\u51FA merchant-list(context=search)\u3002",
|
|
979
|
+
inputSchema: z.object({
|
|
980
|
+
keywords: coerce(z.array(z.string()).min(1).max(5).describe('\u591A\u4E2A\u641C\u7D22\u89D2\u5EA6\uFF0C\u5982 ["\u9178\u5976","\u9178\u5976\u5E97"]')),
|
|
981
|
+
businessCategory: optionalStr("\u4E1A\u6001\u5206\u7C7B\u7F16\u7801\uFF1B\u672A\u77E5\u4F20 null/\u7F3A\u7701"),
|
|
982
|
+
floorCode: optionalStr("\u697C\u5C42\u7F16\u7801\uFF1B\u7528\u6237\u672A\u6307\u5B9A\u65F6\u7F3A\u7701"),
|
|
983
|
+
buildingCode: optionalStr("\u697C\u680B\u7F16\u7801\uFF1B\u7528\u6237\u672A\u6307\u5B9A\u65F6\u7F3A\u7701"),
|
|
984
|
+
...pageFields
|
|
985
|
+
}),
|
|
986
|
+
execute: exec(async (ports, ctx, args) => {
|
|
987
|
+
const q = toContext(ctx);
|
|
988
|
+
const { page, pageSize } = parsePage(args.page, args.pageSize);
|
|
989
|
+
const result = await ports.merchant.searchMerchants({
|
|
990
|
+
ctx: q,
|
|
991
|
+
keyword: args.keywords?.join(" ") ?? "",
|
|
992
|
+
keywords: args.keywords,
|
|
993
|
+
...args.businessCategory && args.businessCategory !== "null" ? { businessCategory: String(args.businessCategory) } : {},
|
|
994
|
+
...args.floorCode && args.floorCode !== "null" ? { floorCode: String(args.floorCode) } : {},
|
|
995
|
+
...args.buildingCode && args.buildingCode !== "null" ? { buildingCode: String(args.buildingCode) } : {},
|
|
996
|
+
page,
|
|
997
|
+
pageSize
|
|
998
|
+
});
|
|
999
|
+
return projectMerchantList(
|
|
1000
|
+
"search",
|
|
1001
|
+
result,
|
|
1002
|
+
result.items.length === 0 ? "\u672A\u627E\u5230\u5339\u914D\u7684\u95E8\u5E97\u3002" : void 0
|
|
1003
|
+
);
|
|
1004
|
+
})
|
|
1005
|
+
});
|
|
1006
|
+
const getMerchant = createTool({
|
|
1007
|
+
id: "get-merchant",
|
|
1008
|
+
description: "\u95E8\u5E97\u8BE6\u60C5\uFF1A\u52A0\u8F7D\u5355\u4E2A\u95E8\u5E97\u7684\u5B8C\u6574\u5FEB\u7167\uFF08\u56FE\u7247/\u7B80\u4ECB/\u8054\u7CFB\u65B9\u5F0F\uFF09\u3002\u4EC5\u5F53\u7528\u6237\u70B9\u51FB\u95E8\u5E97\u5361\u7247\u8981\u770B\u8BE6\u60C5\u65F6\u8C03\u7528\u3002\u8F93\u51FA merchant-detail\u3002",
|
|
1009
|
+
inputSchema: z.object({ merchantId: str("\u95E8\u5E97 ID\uFF08\u6765\u81EA\u641C\u7D22\u7ED3\u679C\u5361\uFF09") }),
|
|
1010
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1011
|
+
const merchant = await ports.merchant.getMerchant(String(args.merchantId), toContext(ctx));
|
|
1012
|
+
if (!merchant) {
|
|
1013
|
+
return { error: "\u672A\u627E\u5230\u8BE5\u95E8\u5E97\u3002" };
|
|
1014
|
+
}
|
|
1015
|
+
return projectMerchantDetail(merchant);
|
|
1016
|
+
})
|
|
1017
|
+
});
|
|
1018
|
+
const mallDirectory = createTool({
|
|
1019
|
+
id: "mall-directory",
|
|
1020
|
+
description: "\u5546\u573A\u697C\u5C42\u76EE\u5F55\uFF1A\u52A0\u8F7D\u5168\u5546\u573A\u697C\u680B-\u697C\u5C42\u7ED3\u6784\uFF08\u56DE\u7B54\u300C\u51E0\u697C\u6709\u4EC0\u4E48\u300D\u7C7B\u95EE\u9898\uFF09\u3002\u8F93\u51FA mall-directory\u3002",
|
|
1021
|
+
inputSchema: z.object({}),
|
|
1022
|
+
execute: exec(async (ports, ctx, _args) => {
|
|
1023
|
+
const directory = await ports.directory.getDirectory(toContext(ctx));
|
|
1024
|
+
if (!directory) {
|
|
1025
|
+
return { error: "\u6682\u65E0\u5546\u573A\u76EE\u5F55\u6570\u636E\u3002" };
|
|
1026
|
+
}
|
|
1027
|
+
return projectMallDirectory(directory);
|
|
1028
|
+
})
|
|
1029
|
+
});
|
|
1030
|
+
const getLocation = createTool({
|
|
1031
|
+
id: "get-location",
|
|
1032
|
+
description: "\u4F4D\u7F6E\u5BFC\u822A\uFF1A\u83B7\u53D6\u6307\u5B9A\u95E8\u5E97\u7684\u4F4D\u7F6E\u4FE1\u606F\u53CA\u5BFC\u822A\u80FD\u529B\uFF08\u4EC5\u5728\u7528\u6237\u660E\u786E\u8981\u6C42\u300C\u5BFC\u822A/\u600E\u4E48\u8D70\u300D\u65F6\u8C03\u7528\uFF09\u3002\u8F93\u51FA location-handoff\u3002",
|
|
1033
|
+
inputSchema: z.object({ merchantId: str("\u95E8\u5E97 ID") }),
|
|
1034
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1035
|
+
const merchant = await ports.merchant.getMerchant(String(args.merchantId), toContext(ctx));
|
|
1036
|
+
if (!merchant) {
|
|
1037
|
+
return { error: "\u672A\u627E\u5230\u8BE5\u95E8\u5E97\u3002" };
|
|
1038
|
+
}
|
|
1039
|
+
return projectLocationHandoff(merchant);
|
|
1040
|
+
})
|
|
1041
|
+
});
|
|
1042
|
+
const listHumanGuides = createTool({
|
|
1043
|
+
id: "list-human-guides",
|
|
1044
|
+
description: "\u4EBA\u5DE5\u5BFC\u8D2D\uFF1A\u5217\u51FA\u6307\u5B9A\u95E8\u5E97\u7684\u53EF\u8054\u7CFB\u5BFC\u8D2D\u5458\uFF08\u4EC5\u5728\u7528\u6237\u660E\u786E\u8981\u6C42\u8054\u7CFB\u4EBA\u5DE5\u65F6\u8C03\u7528\uFF09\u3002\u8F93\u51FA human-guide-list\u3002",
|
|
1045
|
+
inputSchema: z.object({ merchantId: str("\u95E8\u5E97 ID") }),
|
|
1046
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1047
|
+
const merchant = await ports.merchant.getMerchant(String(args.merchantId), toContext(ctx));
|
|
1048
|
+
const guides = await ports.assistance.listHumanGuides(String(args.merchantId), toContext(ctx));
|
|
1049
|
+
return projectHumanGuideList(String(args.merchantId), merchant?.name ?? "\u95E8\u5E97", guides);
|
|
1050
|
+
})
|
|
1051
|
+
});
|
|
1052
|
+
const listBrowsingHistory = createTool({
|
|
1053
|
+
id: "list-browsing-history",
|
|
1054
|
+
description: "\u6D4F\u89C8\u5386\u53F2\uFF1A\u52A0\u8F7D\u5DF2\u767B\u5F55\u7528\u6237\u7684\u5546\u54C1\u6D4F\u89C8\u8BB0\u5F55\u3002\u8F93\u51FA product-list(context=history)\u3002",
|
|
1055
|
+
inputSchema: z.object(pageFields),
|
|
1056
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1057
|
+
const { page, pageSize } = parsePage(args.page, args.pageSize);
|
|
1058
|
+
const result = await ports.navigation.listBrowsingHistory(toContext(ctx), page, pageSize);
|
|
1059
|
+
return projectProductList("history", result);
|
|
1060
|
+
})
|
|
1061
|
+
});
|
|
1062
|
+
const listNearbyMalls = createTool({
|
|
1063
|
+
id: "list-nearby-malls",
|
|
1064
|
+
description: "\u9644\u8FD1\u5546\u573A\uFF1A\u67E5\u8BE2\u9644\u8FD1\u53EF\u5207\u6362\u7684\u5927\u60A6\u57CE\u95E8\u5E97\u5217\u8868\u3002\u8F93\u51FA nearby-mall-list\u3002",
|
|
1065
|
+
inputSchema: z.object({ query: optionalStr("\u57CE\u5E02\u6216\u4F4D\u7F6E\u63D0\u793A\uFF1B\u7F3A\u7701\u4F7F\u7528\u9ED8\u8BA4\u4F4D\u7F6E") }),
|
|
1066
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1067
|
+
if (!ctx.runtime.isFeatureEnabled("navigation")) {
|
|
1068
|
+
return { error: "\u5BFC\u822A\u529F\u80FD\u672A\u542F\u7528\uFF08\u90E8\u7F72\u672A\u5F00\u542F navigation feature\uFF09" };
|
|
1069
|
+
}
|
|
1070
|
+
const malls = await ports.navigation.listNearbyMalls(
|
|
1071
|
+
toContext(ctx),
|
|
1072
|
+
args.query ? String(args.query) : void 0
|
|
1073
|
+
);
|
|
1074
|
+
return projectNearbyMalls(malls, args.query ? String(args.query) : void 0);
|
|
1075
|
+
})
|
|
1076
|
+
});
|
|
1077
|
+
const listCategories = createTool({
|
|
1078
|
+
id: "list-categories",
|
|
1079
|
+
description: "\u5546\u4E1A\u54C1\u7C7B\u76EE\u5F55\uFF1A\u5217\u51FA\u5546\u573A\u5168\u90E8\u4E1A\u6001\u5206\u7C7B\uFF08\u9910\u996E/\u96F6\u552E/\u5A31\u4E50\u7B49\uFF09\uFF0C\u56DE\u7B54\u300C\u5546\u573A\u6709\u54EA\u4E9B\u7C7B\u578B\u7684\u5E97\u300D\u7C7B\u95EE\u9898\u3002\u8F93\u51FA category-list\u3002",
|
|
1080
|
+
inputSchema: z.object({}),
|
|
1081
|
+
execute: exec(async (ports, ctx, _args) => {
|
|
1082
|
+
return projectCategoryList(await ports.category.listCategories(toContext(ctx)));
|
|
1083
|
+
})
|
|
1084
|
+
});
|
|
1085
|
+
const searchKnowledge = createTool({
|
|
1086
|
+
id: "search-knowledge",
|
|
1087
|
+
description: "\u77E5\u8BC6\u5E93\u68C0\u7D22\uFF1A\u8BED\u4E49\u641C\u7D22\u5546\u573A\u8BBE\u65BD/\u653F\u7B56/\u9009\u8D2D\u6307\u5357\u7B49\u7A33\u5B9A\u77E5\u8BC6\u5185\u5BB9\uFF08\u4E0D\u7528\u4E8E\u4EF7\u683C/\u5E93\u5B58/\u5B9E\u65F6\u4FE1\u606F\uFF09\u3002\u8F93\u51FA\u6587\u672C\u6C47\u603B\u3002",
|
|
1088
|
+
inputSchema: z.object({
|
|
1089
|
+
query: str("\u68C0\u7D22\u67E5\u8BE2\u6587\u672C"),
|
|
1090
|
+
topK: optionalStr("\u8FD4\u56DE\u6761\u6570\uFF08\u5B57\u7B26\u4E32\uFF0C1-5\uFF0C\u7F3A\u7701 3\uFF09")
|
|
1091
|
+
}),
|
|
1092
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1093
|
+
const topK = Math.min(5, Math.max(1, Number(args.topK) || 3));
|
|
1094
|
+
const result = await ports.assistance.searchKnowledge(toLooseContext(ctx), String(args.query), topK);
|
|
1095
|
+
return projectKnowledge(result);
|
|
1096
|
+
})
|
|
1097
|
+
});
|
|
1098
|
+
const customerServiceFaq = createTool({
|
|
1099
|
+
id: "customer-service-faq",
|
|
1100
|
+
description: "\u5BA2\u670DFAQ\uFF1A\u641C\u7D22\u5E38\u89C1\u95EE\u9898\u7B54\u6848\uFF08\u9000\u6362\u8D27\u3001\u4F1A\u5458\u79EF\u5206\u3001\u505C\u8F66\u7B49\u670D\u52A1\u653F\u7B56\uFF09\u3002\u8F93\u51FA customer-service-faq\u3002",
|
|
1101
|
+
inputSchema: z.object({
|
|
1102
|
+
query: str("\u7528\u6237\u95EE\u9898"),
|
|
1103
|
+
topK: optionalStr("\u8FD4\u56DE\u6761\u6570\uFF08\u5B57\u7B26\u4E32\uFF0C1-5\uFF0C\u7F3A\u7701 3\uFF09")
|
|
1104
|
+
}),
|
|
1105
|
+
execute: exec(async (ports, ctx, args) => {
|
|
1106
|
+
if (!ctx.runtime.isFeatureEnabled("customer-service")) {
|
|
1107
|
+
return { error: "\u5BA2\u670D\u529F\u80FD\u672A\u542F\u7528\uFF08\u90E8\u7F72\u672A\u5F00\u542F customer-service feature\uFF09" };
|
|
1108
|
+
}
|
|
1109
|
+
const topK = Math.min(5, Math.max(1, Number(args.topK) || 3));
|
|
1110
|
+
const faqs = await ports.assistance.searchFaq(toLooseContext(ctx), String(args.query), topK);
|
|
1111
|
+
return projectCustomerServiceFaq(
|
|
1112
|
+
String(args.query),
|
|
1113
|
+
faqs,
|
|
1114
|
+
faqs.length === 0 ? "\u672A\u627E\u5230\u76F8\u5173\u5E38\u89C1\u95EE\u9898\uFF0C\u8BF7\u5C1D\u8BD5\u4EBA\u5DE5\u5BA2\u670D\u3002" : void 0
|
|
1115
|
+
);
|
|
1116
|
+
})
|
|
1117
|
+
});
|
|
1118
|
+
return {
|
|
1119
|
+
recommend,
|
|
1120
|
+
searchProducts,
|
|
1121
|
+
productFacets,
|
|
1122
|
+
getProduct,
|
|
1123
|
+
compareProducts,
|
|
1124
|
+
searchMerchants,
|
|
1125
|
+
getMerchant,
|
|
1126
|
+
mallDirectory,
|
|
1127
|
+
getLocation,
|
|
1128
|
+
listHumanGuides,
|
|
1129
|
+
listBrowsingHistory,
|
|
1130
|
+
listNearbyMalls,
|
|
1131
|
+
listCategories,
|
|
1132
|
+
searchKnowledge,
|
|
1133
|
+
customerServiceFaq
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// src/server/integrations/joycity/auth-strategy.ts
|
|
1138
|
+
import { createHash } from "crypto";
|
|
1139
|
+
var JOYCITY_C_SIGNED_CREDENTIAL_TYPE = "joycity-c-signed-v1";
|
|
1140
|
+
var joycityCSignedAuthStrategy = {
|
|
1141
|
+
credentialType: JOYCITY_C_SIGNED_CREDENTIAL_TYPE,
|
|
1142
|
+
apply(input) {
|
|
1143
|
+
const credential = input.credential.value;
|
|
1144
|
+
const publicKey = typeof credential.publicKey === "string" ? credential.publicKey : "";
|
|
1145
|
+
const privateKey = typeof credential.privateKey === "string" ? credential.privateKey : "";
|
|
1146
|
+
const timestamp = String(Date.now());
|
|
1147
|
+
const bodyJson = input.body === void 0 ? "" : JSON.stringify(input.body);
|
|
1148
|
+
return {
|
|
1149
|
+
sign: computeJoyCityCSign(publicKey, timestamp, bodyJson, privateKey),
|
|
1150
|
+
timestamp,
|
|
1151
|
+
publickey: publicKey
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
};
|
|
1155
|
+
function computeJoyCityCSign(publicKey, timestamp, bodyJson, privateKey) {
|
|
1156
|
+
const source = `{publicKey:${publicKey},timeStamp:${timestamp},data:${bodyJson},privateKey:${privateKey}}`;
|
|
1157
|
+
return createHash("md5").update(source, "utf8").digest("hex").substring(8, 24).toLowerCase();
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/server/cards/index.ts
|
|
1161
|
+
var shoppingGuideCards = {
|
|
1162
|
+
"product-list": meta_default,
|
|
1163
|
+
"product-detail": meta_default2,
|
|
1164
|
+
"merchant-list": meta_default3,
|
|
1165
|
+
"merchant-detail": meta_default4,
|
|
1166
|
+
"category-list": meta_default5,
|
|
1167
|
+
"product-comparison": meta_default6,
|
|
1168
|
+
"mall-directory": meta_default7,
|
|
1169
|
+
"nearby-mall-list": meta_default8,
|
|
1170
|
+
"customer-service-faq": meta_default9,
|
|
1171
|
+
"human-guide-list": meta_default10,
|
|
1172
|
+
"location-handoff": meta_default11
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// src/server/index.ts
|
|
1176
|
+
var moduleCtx;
|
|
1177
|
+
var tools = createShoppingGuideTools({ getCtx: () => moduleCtx });
|
|
1178
|
+
var faqPreTool = definePreTool(tools.customerServiceFaq, {
|
|
1179
|
+
routing: {
|
|
1180
|
+
mode: "keywords",
|
|
1181
|
+
terms: ["\u9000\u6362\u8D27", "\u9000\u8D27", "\u9000\u6B3E", "\u79EF\u5206\u89C4\u5219", "\u505C\u8F66\u8D39", "\u505C\u8F66\u653F\u7B56", "\u4F1A\u5458\u6743\u76CA", "\u53D1\u7968", "\u552E\u540E"]
|
|
1182
|
+
},
|
|
1183
|
+
decide: ({ text }) => text && text.trim().length > 0 ? { decision: "run", args: { query: text, topK: "3" } } : { decision: "skip", reason: "\u7A7A\u6587\u672C" },
|
|
1184
|
+
silent: true
|
|
1185
|
+
});
|
|
1186
|
+
var preTools = {
|
|
1187
|
+
"customer-service-faq": faqPreTool
|
|
1188
|
+
};
|
|
1189
|
+
var shoppingGuideHandler = {
|
|
1190
|
+
id: "shopping-guide",
|
|
1191
|
+
intents: [
|
|
1192
|
+
{
|
|
1193
|
+
// 「附近商场」确定性意图 → 直接出卡(零 LLM)
|
|
1194
|
+
patterns: ["\u9644\u8FD1\u5546\u573A", "\u9644\u8FD1\u5927\u60A6\u57CE", "\u5176\u4ED6\u5546\u573A", "\u5468\u8FB9\u5546\u573A"]
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
// 「商场有哪些类型的店」确定性意图 → 业态目录(零 LLM)
|
|
1198
|
+
patterns: ["\u6709\u54EA\u4E9B\u7C7B\u578B\u7684\u5E97", "\u5546\u573A\u6709\u4EC0\u4E48\u5E97", "\u6709\u54EA\u4E9B\u4E1A\u6001", "\u901B\u4EC0\u4E48"]
|
|
1199
|
+
}
|
|
1200
|
+
],
|
|
1201
|
+
async handle(action, payload) {
|
|
1202
|
+
const ctx = moduleCtx;
|
|
1203
|
+
const ports = await resolveShoppingGuidePorts(ctx);
|
|
1204
|
+
const requestContext = ctx.auth.getContext();
|
|
1205
|
+
if (!requestContext) return { text: "\u8FD0\u884C\u4E0A\u4E0B\u6587\u672A\u7ED1\u5B9A\uFF0C\u8BF7\u91CD\u8BD5", cards: [] };
|
|
1206
|
+
const q = toShoppingQueryContext(requestContext);
|
|
1207
|
+
if (action === "intent") {
|
|
1208
|
+
const text = String(payload ?? "");
|
|
1209
|
+
if (/附近|其他|周边/.test(text)) {
|
|
1210
|
+
const malls = await ports.navigation.listNearbyMalls(q);
|
|
1211
|
+
return {
|
|
1212
|
+
text: malls.length > 0 ? "\u4E3A\u4F60\u627E\u5230\u9644\u8FD1\u7684\u5927\u60A6\u57CE\u95E8\u5E97\uFF1A" : "\u6682\u65E0\u9644\u8FD1\u5546\u573A\u6570\u636E\u3002",
|
|
1213
|
+
cards: [
|
|
1214
|
+
{ cardType: "nearby-mall-list", data: projectNearbyMalls(malls) }
|
|
1215
|
+
]
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
const categories = await ports.category.listCategories(q);
|
|
1219
|
+
return {
|
|
1220
|
+
text: categories.length > 0 ? "\u5546\u573A\u4E1A\u6001\u5206\u5E03\u5982\u4E0B\uFF1A" : "\u6682\u65E0\u4E1A\u6001\u6570\u636E\u3002",
|
|
1221
|
+
cards: [
|
|
1222
|
+
{ cardType: "category-list", data: projectCategoryList(categories) }
|
|
1223
|
+
]
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
if (action === "faq") {
|
|
1227
|
+
const faqs = await ports.assistance.searchFaq(q, String(payload ?? ""), 3);
|
|
1228
|
+
return {
|
|
1229
|
+
text: faqs.length > 0 ? "\u76F8\u5173\u5E38\u89C1\u95EE\u9898\uFF1A" : "\u672A\u627E\u5230\u76F8\u5173\u5E38\u89C1\u95EE\u9898\u3002",
|
|
1230
|
+
cards: [
|
|
1231
|
+
{
|
|
1232
|
+
cardType: "customer-service-faq",
|
|
1233
|
+
data: projectCustomerServiceFaq(String(payload ?? ""), faqs)
|
|
1234
|
+
}
|
|
1235
|
+
]
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
return { text: "", cards: [] };
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
var skills = Object.fromEntries(
|
|
1242
|
+
(await loadModuleSkills("@tbox.cn/app-module-shopping-guide", import.meta.url)).map((s) => [s.name, s])
|
|
1243
|
+
);
|
|
1244
|
+
var serverModule = {
|
|
1245
|
+
declaration: {
|
|
1246
|
+
componentId: "shopping-guide",
|
|
1247
|
+
features: [
|
|
1248
|
+
"merchant-discovery",
|
|
1249
|
+
"product-search",
|
|
1250
|
+
"recommendation",
|
|
1251
|
+
"mall-directory",
|
|
1252
|
+
"customer-service",
|
|
1253
|
+
"navigation"
|
|
1254
|
+
]
|
|
1255
|
+
},
|
|
1256
|
+
cards: {
|
|
1257
|
+
"product-list": meta_default,
|
|
1258
|
+
"product-detail": meta_default2,
|
|
1259
|
+
"merchant-list": meta_default3,
|
|
1260
|
+
"merchant-detail": meta_default4,
|
|
1261
|
+
"category-list": meta_default5,
|
|
1262
|
+
"product-comparison": meta_default6,
|
|
1263
|
+
"mall-directory": meta_default7,
|
|
1264
|
+
"nearby-mall-list": meta_default8,
|
|
1265
|
+
"customer-service-faq": meta_default9,
|
|
1266
|
+
"human-guide-list": meta_default10,
|
|
1267
|
+
"location-handoff": meta_default11
|
|
1268
|
+
},
|
|
1269
|
+
skills,
|
|
1270
|
+
preTools,
|
|
1271
|
+
register(ctx) {
|
|
1272
|
+
moduleCtx = ctx;
|
|
1273
|
+
ctx.authStrategies.register(joycityCSignedAuthStrategy);
|
|
1274
|
+
ctx.cards.registerMap(serverModule.cards);
|
|
1275
|
+
for (const tool of Object.values(tools)) {
|
|
1276
|
+
ctx.tools.register(tool);
|
|
1277
|
+
}
|
|
1278
|
+
ctx.handlers.register(shoppingGuideHandler);
|
|
1279
|
+
const mallBus = ctx.bus;
|
|
1280
|
+
mallBus.subscribe("member.level.changed", ({ userId }) => {
|
|
1281
|
+
void userId;
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
export {
|
|
1287
|
+
SHOPPING_GUIDE_PROVIDER_TEMPLATE_ID,
|
|
1288
|
+
resolveShoppingGuidePorts,
|
|
1289
|
+
createShoppingGuideTools,
|
|
1290
|
+
joycityCSignedAuthStrategy,
|
|
1291
|
+
computeJoyCityCSign,
|
|
1292
|
+
shoppingGuideCards,
|
|
1293
|
+
serverModule
|
|
1294
|
+
};
|