@tbox.cn/app-module-parking 0.2.0 → 0.9.3
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/AGENTS.md +16 -0
- package/README.md +58 -11
- package/dist/chunk-KEUD5YHH.js +1087 -0
- package/dist/chunk-QHLX6WXM.js +2667 -0
- package/dist/client/index.d.ts +17 -3
- package/dist/client/index.js +4 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +14 -4
- package/dist/parking-2S2UPCOF.css +1306 -0
- package/dist/parking-guide-hero-pea-v2-X2O44LPQ.jpg +0 -0
- package/dist/server/index.d.ts +1216 -72
- package/dist/server/index.js +11 -3
- package/package.json +24 -16
- package/skills/parking/SKILL.md +165 -0
- package/skills/parking/references/payment-safety.md +25 -0
- package/src/client/assets/parking-guide-hero-pea-v2.jpg +0 -0
- package/src/client/assets/parking-guide-hero.jpg +0 -0
- package/src/client/assets.d.ts +5 -0
- package/src/client/cards/index.ts +8 -0
- package/src/client/cards/parking-info/index.tsx +41 -0
- package/src/client/cards/parking-payment/benefit-selection.ts +79 -0
- package/src/client/cards/parking-payment/index.tsx +442 -0
- package/src/client/cards/parking-payment-records/index.tsx +259 -0
- package/src/client/cards/parking-payment-result/index.tsx +83 -0
- package/src/client/cards/parking-vehicle-management/PlateKeyboard.tsx +106 -0
- package/src/client/cards/parking-vehicle-management/index.tsx +344 -0
- package/src/client/cards/parking-vehicle-management/plate-keyboard.ts +113 -0
- package/src/client/cards/view.ts +83 -0
- package/src/client/index.ts +19 -4
- package/src/client/styles/parking.css +1306 -0
- package/src/client/types/css.d.ts +2 -0
- package/src/server/actions.ts +975 -0
- package/src/server/cards/index.ts +14 -0
- package/src/server/cards/parking-info/meta.ts +19 -0
- package/src/server/cards/parking-info/samples.ts +50 -0
- package/src/server/cards/parking-payment/meta.ts +29 -0
- package/src/server/cards/parking-payment/samples.ts +311 -0
- package/src/server/cards/parking-payment-records/meta.ts +32 -0
- package/src/server/cards/parking-payment-records/samples.ts +86 -0
- package/src/server/cards/parking-payment-result/meta.ts +21 -0
- package/src/server/cards/parking-payment-result/samples.ts +84 -0
- package/src/server/cards/parking-vehicle-management/meta.ts +20 -0
- package/src/server/cards/parking-vehicle-management/samples.ts +73 -0
- package/src/server/domain.ts +279 -0
- package/src/server/handler.ts +47 -16
- package/src/server/index.ts +97 -17
- package/src/server/intent-context.ts +14 -0
- package/src/server/ports.ts +59 -0
- package/src/server/service.ts +474 -45
- package/src/server/tools.ts +846 -0
- package/tbox.module.json +107 -0
- package/tests/benefit-selection.test.ts +70 -0
- package/tests/cards-render.test.tsx +643 -0
- package/tests/dispatcher-flow.test.ts +256 -0
- package/tests/payment-flow.test.ts +420 -0
- package/tests/plate-keyboard.test.ts +158 -0
- package/tests/ports-resolve.test.ts +113 -0
- package/tests/pretool-parking-fee.test.ts +104 -0
- package/tests/samples.test.ts +44 -0
- package/tests/skills.test.ts +37 -0
- package/tests/tools-gate.test.ts +237 -0
- package/tests/tools-membership.test.ts +91 -0
- package/tests/view.test.ts +61 -0
- package/tsup.config.ts +9 -1
- package/dist/chunk-BYD3C6NE.js +0 -140
- package/dist/chunk-QQLBZY6D.js +0 -55
- package/src/client/cards/parking-fee/index.tsx +0 -59
- package/src/server/cards/parking-fee/meta.ts +0 -26
- package/src/server/tool.ts +0 -36
- package/tbox.component.json +0 -20
- package/tests/service.test.ts +0 -49
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parking 工具集(聚合卡方案:9 个只读工具;路由词进 description 供 BM25)。
|
|
3
|
+
* 出卡(v2 契约):出参 cards 字段声明 cardType,data 形状与 parkingCardDataSchemas 对齐;
|
|
4
|
+
* found:false 等无价值结果分支不产 cards(不出卡语义)。
|
|
5
|
+
* 上下文统一化:运行上下文 = 工具 execute 第二参(requireToolRequestContext 显式读取);
|
|
6
|
+
* 查询恒实时(W4)。
|
|
7
|
+
*/
|
|
8
|
+
import { createTool, coerceStringifiedFields, withCardEmissionHint } from '@tbox.cn/app-sdk/server';
|
|
9
|
+
import type { ServerContext, ToolExecContextLike } from '@tbox.cn/app-sdk/server';
|
|
10
|
+
import { requireToolRequestContext } from '@tbox.cn/app-sdk/server';
|
|
11
|
+
import { resolveMemberGate, toMallQueryContext } from '@tbox.cn/app-contracts-mall';
|
|
12
|
+
import type {
|
|
13
|
+
MemberBenefitsFactory,
|
|
14
|
+
MemberGateCard,
|
|
15
|
+
MemberStatusFactory,
|
|
16
|
+
ParkingBenefit,
|
|
17
|
+
ParkingPaymentPort,
|
|
18
|
+
ParkingPaymentRecord,
|
|
19
|
+
ParkingQueryContext,
|
|
20
|
+
ParkingQueryPort,
|
|
21
|
+
ParkingVehiclePort,
|
|
22
|
+
QuoteSnapshot,
|
|
23
|
+
} from '@tbox.cn/app-contracts-mall';
|
|
24
|
+
import type { RequestContext } from '@tbox.cn/app-contracts';
|
|
25
|
+
import { z } from 'zod';
|
|
26
|
+
import { resolveParkingPaymentPort, resolveParkingQueryPort } from './ports';
|
|
27
|
+
import {
|
|
28
|
+
PARKING_RECORDS_CAVEATS,
|
|
29
|
+
formatCents,
|
|
30
|
+
autoSettleOnPaidEvidence,
|
|
31
|
+
loadQuotePayment,
|
|
32
|
+
loadLatestOwnedPaymentOperation,
|
|
33
|
+
cacheQuote,
|
|
34
|
+
settlePaymentOperation,
|
|
35
|
+
} from './domain';
|
|
36
|
+
import type { StoreLike } from './domain';
|
|
37
|
+
import { receiptDetails } from './actions';
|
|
38
|
+
|
|
39
|
+
function coerce<T extends z.ZodTypeAny>(schema: T): T {
|
|
40
|
+
return z.preprocess(coerceStringifiedFields, schema) as unknown as T;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function toParkingQueryContext(
|
|
44
|
+
reqCtx: RequestContext,
|
|
45
|
+
): { q: ParkingQueryContext; reqCtx: RequestContext } {
|
|
46
|
+
return { q: toMallQueryContext(reqCtx), reqCtx };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 出卡出参组装(v2 契约):顶层答话事实 + cards 声明(data = 事实本体,不含 cards 键) */
|
|
50
|
+
function withCards<T extends Record<string, unknown>>(
|
|
51
|
+
facts: T,
|
|
52
|
+
cardType: string,
|
|
53
|
+
note: string,
|
|
54
|
+
): T & { cards: unknown[] } {
|
|
55
|
+
return { ...facts, cards: [{ cardType, data: facts, note }] };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function durationText(entryAt?: string): string | undefined {
|
|
59
|
+
if (!entryAt) return undefined;
|
|
60
|
+
const hours = (Date.now() - new Date(entryAt).getTime()) / 3600_000;
|
|
61
|
+
return `${Math.max(1, Math.round(hours))} 小时`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 会员状态投影(上下文统一化):跨模块双注册口消费——
|
|
66
|
+
* 身份判定走 'member.status'(outcome 双轴折叠单源;account 取数 = identity.userId,
|
|
67
|
+
* 与 subjectId 同源——mallSubjectIdOf 派生);积分余额走 'member.service'
|
|
68
|
+
* (TIER1 MemberBenefitsFactory,benefits 面契约)。
|
|
69
|
+
* 不再消费旧 'member' 全局门面(ctx.auth 并发缺陷已拆除)。
|
|
70
|
+
*/
|
|
71
|
+
export async function projectMembership(
|
|
72
|
+
ctx: ServerContext,
|
|
73
|
+
reqCtx: import('@tbox.cn/app-contracts').RequestContext,
|
|
74
|
+
subjectId: string | undefined,
|
|
75
|
+
): Promise<{ state: 'unauthenticated' | 'unknown' | 'active' | 'not_enrolled' | 'closed' | 'unavailable'; availablePoints?: number }> {
|
|
76
|
+
if (!subjectId) return { state: 'unauthenticated' };
|
|
77
|
+
const statusFactory = ctx.services.resolve?.('member.status') as MemberStatusFactory | undefined;
|
|
78
|
+
const benefitsFactory = ctx.services.resolve?.('member.service') as MemberBenefitsFactory | undefined;
|
|
79
|
+
if (!statusFactory || !benefitsFactory) return { state: 'unavailable' };
|
|
80
|
+
try {
|
|
81
|
+
const status = await statusFactory(reqCtx);
|
|
82
|
+
if (status.outcome !== 'active') return { state: status.outcome };
|
|
83
|
+
const benefits = await benefitsFactory(reqCtx);
|
|
84
|
+
const snapshot = await benefits.getBenefits(subjectId);
|
|
85
|
+
return { state: 'active', availablePoints: snapshot.availablePoints };
|
|
86
|
+
} catch (error) {
|
|
87
|
+
ctx.logger?.warn(`停车卡会员状态查询失败:err=${(error as Error).message}`);
|
|
88
|
+
return { state: 'unavailable' };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 把 Provider 返回的 ParkingBenefit 列表投影为 parking-payment 卡 selectableBenefits 视图。
|
|
94
|
+
* 字段以 main 版 cards schema 为准:benefitRef / title / autoSelected / description / kind / discountText / exclusiveWithKinds。
|
|
95
|
+
* reprice action 在重选后用它刷新卡。
|
|
96
|
+
* autoSelected 由 quote.appliedBenefits 推导(重选后已应用 vs 未应用);provider 不必预先判定 autoSelected。
|
|
97
|
+
*/
|
|
98
|
+
export function projectSelectableBenefits(
|
|
99
|
+
quote: QuoteSnapshot,
|
|
100
|
+
benefits: readonly ParkingBenefit[],
|
|
101
|
+
_membership: Awaited<ReturnType<typeof projectMembership>>,
|
|
102
|
+
) {
|
|
103
|
+
const appliedRefs = new Set(quote.appliedBenefits.map((b) => b.benefitRef));
|
|
104
|
+
return benefits.map((b) => ({
|
|
105
|
+
benefitRef: b.benefitRef,
|
|
106
|
+
title: b.title,
|
|
107
|
+
autoSelected: appliedRefs.has(b.benefitRef),
|
|
108
|
+
...(b.description ? { description: b.description } : {}),
|
|
109
|
+
...(b.kind ? { kind: b.kind } : {}),
|
|
110
|
+
...(b.estimatedDiscountCents && b.estimatedDiscountCents > 0
|
|
111
|
+
? { discountText: formatCents(b.estimatedDiscountCents) }
|
|
112
|
+
: {}),
|
|
113
|
+
...(b.exclusiveWithKinds && b.exclusiveWithKinds.length > 0
|
|
114
|
+
? { exclusiveWithKinds: [...b.exclusiveWithKinds] }
|
|
115
|
+
: {}),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function projectPaymentOptions(
|
|
120
|
+
quote: QuoteSnapshot,
|
|
121
|
+
benefits: readonly ParkingBenefit[],
|
|
122
|
+
membership: Awaited<ReturnType<typeof projectMembership>>,
|
|
123
|
+
) {
|
|
124
|
+
const pointsBenefits = benefits.filter((benefit) => benefit.kind === 'points');
|
|
125
|
+
const pointsRefs = new Set(pointsBenefits.map((benefit) => benefit.benefitRef));
|
|
126
|
+
const directBenefitRefs = quote.appliedBenefits
|
|
127
|
+
.map((benefit) => benefit.benefitRef)
|
|
128
|
+
.filter((benefitRef) => !pointsRefs.has(benefitRef));
|
|
129
|
+
const direct = {
|
|
130
|
+
...(!quote.appliedBenefits.some((benefit) => pointsRefs.has(benefit.benefitRef))
|
|
131
|
+
? { payableText: formatCents(quote.payableCents) }
|
|
132
|
+
: {}),
|
|
133
|
+
benefitRefs: directBenefitRefs,
|
|
134
|
+
};
|
|
135
|
+
if (membership.state !== 'active' || pointsBenefits.length === 0) return { direct };
|
|
136
|
+
|
|
137
|
+
const pointsBenefit = pointsBenefits[0]!;
|
|
138
|
+
if (
|
|
139
|
+
pointsBenefit.requiredPoints &&
|
|
140
|
+
membership.availablePoints !== undefined &&
|
|
141
|
+
membership.availablePoints < pointsBenefit.requiredPoints
|
|
142
|
+
) {
|
|
143
|
+
return { direct };
|
|
144
|
+
}
|
|
145
|
+
const benefitRefs = [...new Set([...directBenefitRefs, pointsBenefit.benefitRef])];
|
|
146
|
+
const points =
|
|
147
|
+
pointsBenefit.requiredPoints &&
|
|
148
|
+
pointsBenefit.previewPayableCents !== undefined &&
|
|
149
|
+
membership.availablePoints !== undefined &&
|
|
150
|
+
membership.availablePoints >= pointsBenefit.requiredPoints
|
|
151
|
+
? {
|
|
152
|
+
kind: 'exact' as const,
|
|
153
|
+
pointsToUse: pointsBenefit.requiredPoints,
|
|
154
|
+
payableText: formatCents(pointsBenefit.previewPayableCents),
|
|
155
|
+
benefitRefs,
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
kind: 'requires_reprice' as const,
|
|
159
|
+
title: pointsBenefit.title,
|
|
160
|
+
benefitRefs,
|
|
161
|
+
};
|
|
162
|
+
return { direct, points };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* quote → parking-payment 卡 facts。工具 queryParkingFee 与意图 handler 的 query-fee 共用:
|
|
167
|
+
* 两条入口回答的是同一个问题(我的停车费多少),就该给同一张卡。曾经 handler 另出一张
|
|
168
|
+
* 简化的 parking-info「待支付单」,用户按走哪条路径看到两种形态、且简化卡没有缴费入口。
|
|
169
|
+
*/
|
|
170
|
+
export async function buildParkingPaymentFacts(input: {
|
|
171
|
+
ctx: ServerContext;
|
|
172
|
+
reqCtx: RequestContext;
|
|
173
|
+
q: ParkingQueryContext;
|
|
174
|
+
state: StoreLike;
|
|
175
|
+
quote: QuoteSnapshot;
|
|
176
|
+
}) {
|
|
177
|
+
const quote = input.quote;
|
|
178
|
+
// W4:仅未支付态缓存(confirm revision CAS 依赖);已支付态命中 → 自动收口悬挂 PAYING
|
|
179
|
+
const owner = paymentOwner(input.q);
|
|
180
|
+
if (owner) await cacheQuote(input.state, quote, owner);
|
|
181
|
+
const paidRef =
|
|
182
|
+
quote.paymentState === 'PAID' && owner
|
|
183
|
+
? await loadQuotePayment(input.state, quote.quoteRef, owner)
|
|
184
|
+
: undefined;
|
|
185
|
+
await autoSettleOnPaidEvidence(input.state, quote, paidRef ?? undefined);
|
|
186
|
+
// 新方案:不再查可用优惠券(queryApplicableBenefits 跳过);支付走跳转小程序确认页,无需权益选择
|
|
187
|
+
const [benefits, membership] = await Promise.all([
|
|
188
|
+
Promise.resolve([] as readonly ParkingBenefit[]),
|
|
189
|
+
projectMembership(input.ctx, input.reqCtx, input.q.subjectId),
|
|
190
|
+
]);
|
|
191
|
+
const facts = {
|
|
192
|
+
found: true as const,
|
|
193
|
+
quoteRef: quote.quoteRef,
|
|
194
|
+
plateNo: quote.plateNo,
|
|
195
|
+
entryAtText: quote.entryAt
|
|
196
|
+
? new Date(quote.entryAt).toLocaleString('zh-CN')
|
|
197
|
+
: undefined,
|
|
198
|
+
durationText: durationText(quote.entryAt),
|
|
199
|
+
feeItems: quote.feeItems.map((i) => ({
|
|
200
|
+
name: i.name,
|
|
201
|
+
amountText: formatCents(i.amountCents),
|
|
202
|
+
})),
|
|
203
|
+
totalText: formatCents(quote.totalCents),
|
|
204
|
+
discountText:
|
|
205
|
+
quote.discountCents > 0
|
|
206
|
+
? formatCents(quote.discountCents)
|
|
207
|
+
: undefined,
|
|
208
|
+
payableText: formatCents(quote.payableCents),
|
|
209
|
+
membership,
|
|
210
|
+
paymentOptions: projectPaymentOptions(quote, benefits, membership),
|
|
211
|
+
appliedBenefits: quote.appliedBenefits.map((b) => ({
|
|
212
|
+
benefitRef: b.benefitRef,
|
|
213
|
+
title: b.title,
|
|
214
|
+
discountText:
|
|
215
|
+
b.discountCents > 0 ? formatCents(b.discountCents) : undefined,
|
|
216
|
+
})),
|
|
217
|
+
selectableBenefits: benefits.map((b) => ({
|
|
218
|
+
benefitRef: b.benefitRef,
|
|
219
|
+
title: b.title,
|
|
220
|
+
autoSelected: b.autoSelected,
|
|
221
|
+
...(b.description ? { description: b.description } : {}),
|
|
222
|
+
// 类型与互斥标记由 provider 归一化下发;客户端据此分组、判定互斥,不作推断
|
|
223
|
+
...(b.kind ? { kind: b.kind } : {}),
|
|
224
|
+
...(b.estimatedDiscountCents && b.estimatedDiscountCents > 0
|
|
225
|
+
? { discountText: formatCents(b.estimatedDiscountCents) }
|
|
226
|
+
: {}),
|
|
227
|
+
...(b.exclusiveWithKinds && b.exclusiveWithKinds.length > 0
|
|
228
|
+
? { exclusiveWithKinds: [...b.exclusiveWithKinds] }
|
|
229
|
+
: {}),
|
|
230
|
+
})),
|
|
231
|
+
revision: quote.revision,
|
|
232
|
+
caveats: ['费用以出场实际计费为准', '权益以厂商核验结果为准'],
|
|
233
|
+
// 待支付订单提示:让 LLM 知道这是待支付订单而非新报价,引导用户点击卡片支付
|
|
234
|
+
...(quote.payHandoff?.kind === 'unpaid'
|
|
235
|
+
? { pendingOrderNotice: `您的车(${quote.plateNo})有一笔待支付停车订单,请点击卡片上的支付按钮完成缴费` }
|
|
236
|
+
: {}),
|
|
237
|
+
// 支付交接:有 payHandoff(kind 判 openParkingPay/openParkingUnpaidOrder)时客户端卡走 tbox 能力,无则走内部 confirm-payment
|
|
238
|
+
...(quote.payHandoff
|
|
239
|
+
? { payHandoff: quote.payHandoff }
|
|
240
|
+
: {}),
|
|
241
|
+
};
|
|
242
|
+
return facts;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 会员门禁(属人查询预收口):provider 声明 ParkingQueryPort.requiresMembership 能力口
|
|
247
|
+
* 且当前凭证不足时,经 member.status 投影门禁卡;未声明能力口(mock)→ 不拦;
|
|
248
|
+
* member 未装 / unknown / unavailable → fail-open(不误伤瞬时故障的会员)。
|
|
249
|
+
* 零额外 RTT 依据:member.status 的 getAccount 在真实厂商档均为纯本地凭证判定。
|
|
250
|
+
*/
|
|
251
|
+
export async function parkingMembershipGate(
|
|
252
|
+
ctx: ServerContext,
|
|
253
|
+
reqCtx: import('@tbox.cn/app-contracts').RequestContext,
|
|
254
|
+
q: ParkingQueryContext,
|
|
255
|
+
service: ParkingQueryPort | ParkingPaymentPort | ParkingVehiclePort,
|
|
256
|
+
): Promise<{ card?: MemberGateCard; notice: string } | undefined> {
|
|
257
|
+
// requiresMembership 是 query 槽能力口:payment/vehicle 槽服务也可能来自共享 fat 实现,
|
|
258
|
+
// 运行期 typeof 探测(未声明即 fail-open,行为与拆分前一致)
|
|
259
|
+
const requires =
|
|
260
|
+
typeof (service as ParkingQueryPort).requiresMembership === 'function' &&
|
|
261
|
+
(service as ParkingQueryPort).requiresMembership!(q);
|
|
262
|
+
if (!requires) return undefined;
|
|
263
|
+
return resolveMemberGate(
|
|
264
|
+
ctx.services?.resolve?.('member.status') as MemberStatusFactory | undefined,
|
|
265
|
+
reqCtx,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function createParkingTools(opts: { getCtx: () => ServerContext }) {
|
|
270
|
+
/** 工具 execute 第二参 → 请求级 parking 槽服务(require 变体 fail-visible:缺上下文即报错)。
|
|
271
|
+
* 017 槽位原子化:按工具语义选槽 resolver——查询族 → parking.query;
|
|
272
|
+
* 支付状态回查(reconcile)→ parking.payment。 */
|
|
273
|
+
const serviceOf = async <T>(
|
|
274
|
+
execCtx: ToolExecContextLike,
|
|
275
|
+
resolve: (reqCtx: RequestContext, ctx: ServerContext) => Promise<T>,
|
|
276
|
+
): Promise<{
|
|
277
|
+
service: T;
|
|
278
|
+
q: ParkingQueryContext;
|
|
279
|
+
state: StoreLike;
|
|
280
|
+
reqCtx: RequestContext;
|
|
281
|
+
}> => {
|
|
282
|
+
const ctx = opts.getCtx();
|
|
283
|
+
const reqCtx = requireToolRequestContext(execCtx);
|
|
284
|
+
const c = toParkingQueryContext(reqCtx);
|
|
285
|
+
const service = await resolve(c.reqCtx, ctx);
|
|
286
|
+
return { service, q: c.q, state: ctx.state as unknown as StoreLike, reqCtx: c.reqCtx };
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// ===== 1. queryParkingFee → parking-payment 卡 =====
|
|
290
|
+
const queryParkingFee = createTool({
|
|
291
|
+
id: 'queryParkingFee',
|
|
292
|
+
description:
|
|
293
|
+
'查询停车费报价(缴费、停车费多少钱、应付金额、停车缴费、待支付停车单、出场费)。输入车牌号(或绑定车辆引用/Barcode),返回报价快照(费用明细、已享权益、应付金额、revision)与缴费操作指引。仅支持查询本人绑定车辆——传入的 plateNo 必须在 listVehicles 返回的绑定列表中,非绑定车牌将被拒绝。用户说「我的车」「查一下停车费」未指定车牌时,将自动扫描所有绑定车辆,返回**所有**在场有费车辆的报价(每辆一张缴费卡),无需逐辆重试。',
|
|
294
|
+
inputSchema: coerce(
|
|
295
|
+
z.object({
|
|
296
|
+
plateNo: z
|
|
297
|
+
.string()
|
|
298
|
+
.optional()
|
|
299
|
+
.describe(
|
|
300
|
+
'完整车牌由用户提供或 listVehicles 返回,禁止自行编写示例车牌;用户说「我的车」或提到多个车牌时**可不传**,服务端自动扫描所有绑定车返回全部在场车辆报价',
|
|
301
|
+
),
|
|
302
|
+
vehicleRef: z
|
|
303
|
+
.string()
|
|
304
|
+
.optional()
|
|
305
|
+
.describe(
|
|
306
|
+
'绑定车辆引用(列表结果中的 vehicleRef);若指定车辆已不在场,自动回退扫描其它绑定车',
|
|
307
|
+
),
|
|
308
|
+
barcode: z.string().optional().describe('入场小票条码'),
|
|
309
|
+
}),
|
|
310
|
+
),
|
|
311
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
312
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
313
|
+
// 会员门禁(属人读工具):未入会 → CTA 卡(mall 模板半屏闭环);requiresMembership 缺席/软态放行
|
|
314
|
+
const gate = await parkingMembershipGate(opts.getCtx(), s.reqCtx as never, s.q, s.service);
|
|
315
|
+
if (gate)
|
|
316
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
317
|
+
// 非绑定车牌拒查:显式 plateNo 先校验是否在本人绑定列表中,未绑定不查费
|
|
318
|
+
const explicitPlate = args.plateNo as string | undefined;
|
|
319
|
+
if (explicitPlate) {
|
|
320
|
+
const { bound } = await s.service.listVehicles(s.q);
|
|
321
|
+
const normalized = explicitPlate.trim().toUpperCase();
|
|
322
|
+
if (!bound.some((v) => v.plateNo.toUpperCase() === normalized)) {
|
|
323
|
+
return {
|
|
324
|
+
found: false as const,
|
|
325
|
+
message: `车牌 ${explicitPlate} 不在您的绑定车辆列表中,仅支持查询本人绑定车辆的停车费`,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const quotes = await s.service.queryFee(s.q, {
|
|
330
|
+
plateNo: explicitPlate,
|
|
331
|
+
vehicleRef: args.vehicleRef as string | undefined,
|
|
332
|
+
barcode: args.barcode as string | undefined,
|
|
333
|
+
});
|
|
334
|
+
if (quotes.length === 0)
|
|
335
|
+
return {
|
|
336
|
+
found: false,
|
|
337
|
+
message: '未找到在场车辆(可能未入场或已出场)',
|
|
338
|
+
}; // 无 cards:不出卡
|
|
339
|
+
// 多辆在场车:逐辆出 parking-payment 卡(各绑独立 quoteRef,缴费操作互不影响)
|
|
340
|
+
const cards: unknown[] = [];
|
|
341
|
+
const factsList: Record<string, unknown>[] = [];
|
|
342
|
+
for (const quote of quotes) {
|
|
343
|
+
const facts = await buildParkingPaymentFacts({
|
|
344
|
+
ctx: opts.getCtx(),
|
|
345
|
+
reqCtx: requireToolRequestContext(execCtx),
|
|
346
|
+
q: s.q,
|
|
347
|
+
state: s.state,
|
|
348
|
+
quote,
|
|
349
|
+
});
|
|
350
|
+
factsList.push(facts);
|
|
351
|
+
cards.push({
|
|
352
|
+
cardType: 'parking-payment',
|
|
353
|
+
data: facts,
|
|
354
|
+
note: `${quote.plateNo} 停车费 ${formatCents(quote.payableCents)}${
|
|
355
|
+
durationText(quote.entryAt) ? ` · 已停 ${durationText(quote.entryAt)}` : ''
|
|
356
|
+
}`,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
const primary = factsList[0] as Record<string, unknown>;
|
|
360
|
+
return { ...primary, cards };
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// ===== 2. listVehicles → parking-vehicle-management 卡 =====
|
|
365
|
+
const listVehicles = createTool({
|
|
366
|
+
id: 'listVehicles',
|
|
367
|
+
description:
|
|
368
|
+
'查询我的车辆(绑定车辆、我的车牌、车辆管理)——已绑车辆列表,支持添加/解绑车辆。',
|
|
369
|
+
inputSchema: z.object({}),
|
|
370
|
+
execute: async (_args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
371
|
+
const ctx = opts.getCtx();
|
|
372
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
373
|
+
// 会员门禁(属人读工具)
|
|
374
|
+
const gate = await parkingMembershipGate(ctx, s.reqCtx as never, s.q, s.service);
|
|
375
|
+
if (gate)
|
|
376
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
377
|
+
const [{ bound }, membership] = await Promise.all([
|
|
378
|
+
s.service.listVehicles(s.q),
|
|
379
|
+
// 与缴费卡同源:入会引导只在明确 not_enrolled 时出,不臆测
|
|
380
|
+
projectMembership(ctx, requireToolRequestContext(execCtx), s.q.subjectId),
|
|
381
|
+
]);
|
|
382
|
+
const facts = {
|
|
383
|
+
// parked 是可选能力:provider 未给则不落字段,模型与 UI 都不臆测在场状态
|
|
384
|
+
bound: bound.map((v) => ({
|
|
385
|
+
vehicleRef: v.vehicleRef,
|
|
386
|
+
plateNo: v.plateNo,
|
|
387
|
+
...(v.parked === undefined ? {} : { parked: v.parked }),
|
|
388
|
+
})),
|
|
389
|
+
membership: { state: membership.state },
|
|
390
|
+
};
|
|
391
|
+
return withCards(
|
|
392
|
+
facts,
|
|
393
|
+
'parking-vehicle-management',
|
|
394
|
+
`我的车辆(绑定 ${facts.bound.length} 辆)`,
|
|
395
|
+
);
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// ===== 3. listPaymentRecords → parking-payment-records 卡 =====
|
|
400
|
+
const listPaymentRecords = createTool({
|
|
401
|
+
id: 'listPaymentRecords',
|
|
402
|
+
description:
|
|
403
|
+
'查询停车缴费记录(缴费历史、停车订单、付了多少钱、历史停车费)——近 6 个月记录,含金额/时间/状态,可展开入场出场信息。默认查全部状态;仅在用户明确指定交易状态时传 orderStatus 过滤。',
|
|
404
|
+
inputSchema: coerce(
|
|
405
|
+
z.object({
|
|
406
|
+
page: z.coerce.number().int().min(1).optional().describe('页码(从 1 开始)'),
|
|
407
|
+
pageSize: z.coerce.number().int().min(1).max(50).optional().describe('每页条数(缺省 10)'),
|
|
408
|
+
orderStatus: z
|
|
409
|
+
.string()
|
|
410
|
+
.optional()
|
|
411
|
+
.describe(
|
|
412
|
+
'交易状态过滤(逗号分隔多个)。仅在用户语义明确指定时传,缺省=全量。枚举:10/30=待付款 40=付款成功 42=待发货 43=待收货 50=交易成功 60=交易完成 70=交易关闭',
|
|
413
|
+
),
|
|
414
|
+
}),
|
|
415
|
+
),
|
|
416
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
417
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
418
|
+
// 会员门禁(属人读工具):接线在 try 之前——门禁失败不发必然失败的厂商请求
|
|
419
|
+
const gate = await parkingMembershipGate(opts.getCtx(), s.reqCtx as never, s.q, s.service);
|
|
420
|
+
if (gate)
|
|
421
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
422
|
+
const page = Math.max(1, (args.page as number) || 1);
|
|
423
|
+
const pageSize = Math.min(50, Math.max(1, (args.pageSize as number) || 10));
|
|
424
|
+
const orderStatus = typeof args.orderStatus === 'string' ? args.orderStatus.trim() : undefined;
|
|
425
|
+
try {
|
|
426
|
+
const result = await s.service.listPaymentRecords(s.q, page, pageSize, orderStatus);
|
|
427
|
+
const facts = {
|
|
428
|
+
items: result.items.map(recordCardItem),
|
|
429
|
+
total: result.total,
|
|
430
|
+
hasMore: result.hasMore,
|
|
431
|
+
caveats: [...PARKING_RECORDS_CAVEATS],
|
|
432
|
+
};
|
|
433
|
+
return withCards(
|
|
434
|
+
facts,
|
|
435
|
+
'parking-payment-records',
|
|
436
|
+
`停车缴费记录(共 ${result.total} 条)`,
|
|
437
|
+
);
|
|
438
|
+
} catch {
|
|
439
|
+
return { found: false, message: '暂时无法查询停车缴费记录,请稍后再试' };
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// ===== 4. queryParkingInfo → parking-info 卡(四合一) =====
|
|
445
|
+
const queryParkingInfo = createTool({
|
|
446
|
+
id: 'queryParkingInfo',
|
|
447
|
+
description:
|
|
448
|
+
'停车场信息查询——kind 三选一:chargeRules 收费规则/收费标准/每小时多少钱(纯文字回答不出卡);benefitPolicy 会员停车权益政策(出 parking-info 卡);vehicleLocation 车场概览(总车位/剩余车位/地址,纯文字回答不出卡)。用户问「还有多少空位/剩余车位/车位」→ vehicleLocation;问「收费规则/怎么收费」→ chargeRules;问「会员停车权益/停车优惠」→ benefitPolicy。待支付停车单请改用 queryParkingFee(出可缴费的报价卡)。回答时按 entries 逐条列出**全部**车场(带 label 与 value),禁止自行筛选、省略或只回一个车场;"暂无数据/占位待公示"的车场也单列,不得整体丢弃。',
|
|
449
|
+
inputSchema: coerce(
|
|
450
|
+
z.object({
|
|
451
|
+
kind: z
|
|
452
|
+
.enum(['chargeRules', 'benefitPolicy', 'vehicleLocation'])
|
|
453
|
+
.describe(
|
|
454
|
+
'信息类型:chargeRules=收费规则;benefitPolicy=会员权益;vehicleLocation=车场概览(余位/总位/地址)',
|
|
455
|
+
),
|
|
456
|
+
}),
|
|
457
|
+
),
|
|
458
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
459
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
460
|
+
try {
|
|
461
|
+
const info = await s.service.queryParkingInfo(
|
|
462
|
+
s.q,
|
|
463
|
+
args.kind as 'chargeRules' | 'benefitPolicy' | 'vehicleLocation',
|
|
464
|
+
);
|
|
465
|
+
const facts = {
|
|
466
|
+
kind: info.kind,
|
|
467
|
+
title: info.title,
|
|
468
|
+
entries: info.entries.map((e) => ({ label: e.label, value: e.value })),
|
|
469
|
+
};
|
|
470
|
+
// vehicleLocation(余位)/chargeRules(收费规则)/benefitPolicy(权益政策)纯文字回答,不出卡
|
|
471
|
+
return facts;
|
|
472
|
+
} catch {
|
|
473
|
+
return { found: false, message: '停车信息查询失败,请稍后再试' };
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// ===== 5. queryApplicableBenefits → parking-info(benefitPolicy)卡 =====
|
|
479
|
+
const queryApplicableBenefits = createTool({
|
|
480
|
+
id: 'queryApplicableBenefits',
|
|
481
|
+
description:
|
|
482
|
+
'查询车辆可用的停车权益(会员折扣、积分抵扣、停车券)——返回可用权益列表与预计抵扣金额,用户可在缴费卡中重新选择。',
|
|
483
|
+
inputSchema: coerce(z.object({ plateNo: z.string().describe('车牌号') })),
|
|
484
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
485
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
486
|
+
// 会员门禁(属人读工具)
|
|
487
|
+
const gate = await parkingMembershipGate(opts.getCtx(), s.reqCtx as never, s.q, s.service);
|
|
488
|
+
if (gate)
|
|
489
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
490
|
+
try {
|
|
491
|
+
const benefits = await s.service.queryApplicableBenefits(
|
|
492
|
+
s.q,
|
|
493
|
+
args.plateNo as string,
|
|
494
|
+
);
|
|
495
|
+
const facts = {
|
|
496
|
+
kind: 'benefitPolicy' as const,
|
|
497
|
+
title: '可用停车权益',
|
|
498
|
+
entries: benefits.map((b) => ({
|
|
499
|
+
label: `${b.title}${b.autoSelected ? '(已默认生效)' : ''}`,
|
|
500
|
+
value: b.estimatedDiscountCents
|
|
501
|
+
? `预计抵扣 ${formatCents(b.estimatedDiscountCents)}`
|
|
502
|
+
: (b.description ?? '可用'),
|
|
503
|
+
})),
|
|
504
|
+
};
|
|
505
|
+
if (benefits.length === 0) {
|
|
506
|
+
return { ...facts, message: `当前车辆(${args.plateNo})暂无可用停车权益` };
|
|
507
|
+
}
|
|
508
|
+
return withCards(
|
|
509
|
+
facts,
|
|
510
|
+
'parking-info',
|
|
511
|
+
`${args.plateNo} 可用权益 ${benefits.length} 项`,
|
|
512
|
+
);
|
|
513
|
+
} catch {
|
|
514
|
+
return { found: false, message: '暂时无法查询停车权益,请稍后再试' };
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// ===== 6. locateVehicle → 暂不出卡,仅文字告知商场未提供寻车能力 =====
|
|
520
|
+
const locateVehicle = createTool({
|
|
521
|
+
id: 'locateVehicle',
|
|
522
|
+
description:
|
|
523
|
+
'寻车(车停哪了、找车、车辆定位)——当前商场暂未开通车位寻找功能,返回车辆所在商场/停车场与说明。仅支持寻车本人绑定车辆,传入的 plateNo 必须在 listVehicles 返回的绑定列表中。' +
|
|
524
|
+
'【出答规则】严格原样复述本工具返回的 text 给用户,不得改写、扩写或添加服务台等额外建议。',
|
|
525
|
+
inputSchema: coerce(z.object({ plateNo: z.string().describe('车牌号') })),
|
|
526
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
527
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
528
|
+
const plateNo = String(args?.plateNo ?? '').trim();
|
|
529
|
+
|
|
530
|
+
// 非绑定车牌拒查:寻车同样只限本人绑定车辆
|
|
531
|
+
if (plateNo) {
|
|
532
|
+
const { bound } = await s.service.listVehicles(s.q);
|
|
533
|
+
const normalized = plateNo.toUpperCase();
|
|
534
|
+
if (!bound.some((v) => v.plateNo.toUpperCase() === normalized)) {
|
|
535
|
+
return {
|
|
536
|
+
text: `车牌 ${plateNo} 不在您的绑定车辆列表中,仅支持寻车本人绑定的车辆。`,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// 优先:借查费链路拿"在场那个车场"——advance 命中场时 fix A 已把车场名回填进 feeItems[0].note。
|
|
542
|
+
// 不读 quote.parkingId:QuoteSnapshot 契约无此字段。在场判定走 feeItems[0].note(契约有 feeItems);
|
|
543
|
+
// 待支付 pending quote 的 feeItems 为空 → 视同不在场。不动 ParkingPresence/QuoteSnapshot 契约。
|
|
544
|
+
if (plateNo) {
|
|
545
|
+
try {
|
|
546
|
+
const quotes = await s.service.queryFee(s.q, { plateNo });
|
|
547
|
+
const quote = quotes[0];
|
|
548
|
+
const lotName = String(quote?.feeItems[0]?.note ?? '').trim();
|
|
549
|
+
if (lotName) {
|
|
550
|
+
return {
|
|
551
|
+
text: `你的车(${plateNo})在${lotName},本商场暂未提供车位寻找功能。`,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
// quote=null 或 quote 无 feeItems[0].note(#buildPendingQuote 待支付 quote feeItems=空)→ 视同不在场
|
|
555
|
+
return {
|
|
556
|
+
text: `查到您的车(${plateNo})目前不在商场停车场内或已离场;本商场暂未提供车位寻找功能。`,
|
|
557
|
+
};
|
|
558
|
+
} catch {
|
|
559
|
+
// 查费链路异常:不能确认在场,更不能误报"在 X 停车场"——避免 20901 等未识别信封码兜底成"在场"。
|
|
560
|
+
return {
|
|
561
|
+
text: `暂时无法确认您的车(${plateNo})是否在商场停车场内;本商场暂未提供车位寻找功能。`,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
let parkName = '当前商场';
|
|
567
|
+
try {
|
|
568
|
+
const info = await s.service.queryParkingInfo(s.q, 'vehicleLocation');
|
|
569
|
+
const mallEntry = info.entries.find((e) => e.label === '商场');
|
|
570
|
+
if (mallEntry?.value) parkName = mallEntry.value;
|
|
571
|
+
else if (info.title) parkName = info.title;
|
|
572
|
+
} catch {
|
|
573
|
+
// 失败时回退默认名称
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
text: `你的车${plateNo ? `(${plateNo})` : ''}当前在${parkName}停车场,本商场暂未提供车位寻找功能。`,
|
|
577
|
+
};
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// ===== 7. listInvoiceableOrders → parking-payment-records 卡 =====
|
|
582
|
+
const listInvoiceableOrders = createTool({
|
|
583
|
+
id: 'listInvoiceableOrders',
|
|
584
|
+
description:
|
|
585
|
+
'查询可开票的停车订单(开发票、开票记录、哪些订单能开发票)——**停车开票功能暂未接入**,模型不应调用此工具;用户问开票时直接告知在商场小程序停车缴费页面操作。',
|
|
586
|
+
inputSchema: coerce(
|
|
587
|
+
z.object({
|
|
588
|
+
page: z.string().optional().describe('页码(字符串)'),
|
|
589
|
+
pageSize: z.string().optional().describe('每页条数(字符串)'),
|
|
590
|
+
}),
|
|
591
|
+
),
|
|
592
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
593
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
594
|
+
// 会员门禁(属人读工具)
|
|
595
|
+
const gate = await parkingMembershipGate(opts.getCtx(), s.reqCtx as never, s.q, s.service);
|
|
596
|
+
if (gate)
|
|
597
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
598
|
+
const page = Math.max(1, Number(args.page) || 1);
|
|
599
|
+
const pageSize = Math.min(50, Math.max(1, Number(args.pageSize) || 10));
|
|
600
|
+
try {
|
|
601
|
+
const result = await s.service.listInvoiceableOrders(s.q, page, pageSize);
|
|
602
|
+
const facts = {
|
|
603
|
+
items: result.items.map(recordCardItem),
|
|
604
|
+
total: result.total,
|
|
605
|
+
hasMore: result.hasMore,
|
|
606
|
+
caveats: [
|
|
607
|
+
...PARKING_RECORDS_CAVEATS,
|
|
608
|
+
'可在卡片中对符合条件的订单申请开票',
|
|
609
|
+
],
|
|
610
|
+
};
|
|
611
|
+
return withCards(
|
|
612
|
+
facts,
|
|
613
|
+
'parking-payment-records',
|
|
614
|
+
`可开票订单(共 ${result.total} 条)`,
|
|
615
|
+
);
|
|
616
|
+
} catch {
|
|
617
|
+
return { found: false, message: '暂时无法查询可开票订单,请稍后再试' };
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
// ===== 8. queryParkingPaymentStatus → parking-payment-result 卡 =====
|
|
623
|
+
const queryParkingPaymentStatus = createTool({
|
|
624
|
+
id: 'queryParkingPaymentStatus',
|
|
625
|
+
description:
|
|
626
|
+
'查询我最近一笔停车支付的权威状态(支付成功了吗、停车费付款结果、支付处理中)。无需传支付单号,仅回查当前用户在当前商场最近发起的支付。',
|
|
627
|
+
inputSchema: z.object({}),
|
|
628
|
+
execute: async (_args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
629
|
+
// reconcile 权威回查 = 支付语义 → parking.payment 槽(017 槽位原子化)
|
|
630
|
+
const s = await serviceOf(execCtx, resolveParkingPaymentPort);
|
|
631
|
+
// 会员门禁(属人读工具):接线在 owner-null 检查之前——GUEST 无 subjectId 会先撞 owner 误导文案
|
|
632
|
+
const gate = await parkingMembershipGate(opts.getCtx(), s.reqCtx as never, s.q, s.service);
|
|
633
|
+
if (gate)
|
|
634
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
635
|
+
const owner = paymentOwner(s.q);
|
|
636
|
+
if (!owner)
|
|
637
|
+
return { found: false, message: '当前会话缺少用户或商场上下文' };
|
|
638
|
+
const op = await loadLatestOwnedPaymentOperation(s.state, owner);
|
|
639
|
+
if (!op)
|
|
640
|
+
return {
|
|
641
|
+
found: false,
|
|
642
|
+
message: '未找到当前用户在本商场发起的停车支付',
|
|
643
|
+
};
|
|
644
|
+
const final = await s.service.reconcile(s.q, op.providerPaymentRef);
|
|
645
|
+
const settled = await settlePaymentOperation(
|
|
646
|
+
s.state,
|
|
647
|
+
op.paymentRef,
|
|
648
|
+
final === 'PAID'
|
|
649
|
+
? 'PAID'
|
|
650
|
+
: final === 'CANCELLED'
|
|
651
|
+
? 'CANCELLED'
|
|
652
|
+
: 'UNKNOWN',
|
|
653
|
+
);
|
|
654
|
+
const current = settled ?? op;
|
|
655
|
+
const status =
|
|
656
|
+
current.status === 'PAID'
|
|
657
|
+
? 'PAID'
|
|
658
|
+
: current.status === 'CANCELLED'
|
|
659
|
+
? 'CANCELLED'
|
|
660
|
+
: 'UNKNOWN';
|
|
661
|
+
const facts = {
|
|
662
|
+
found: true as const,
|
|
663
|
+
paymentRef: current.paymentRef,
|
|
664
|
+
plateNo: current.plateNo,
|
|
665
|
+
status,
|
|
666
|
+
amountText: formatCents(current.payableCents),
|
|
667
|
+
message:
|
|
668
|
+
status === 'PAID'
|
|
669
|
+
? '支付成功'
|
|
670
|
+
: status === 'CANCELLED'
|
|
671
|
+
? '支付已取消,可重新发起'
|
|
672
|
+
: '厂商对账中,请稍后再查询',
|
|
673
|
+
// CANCELLED 是终态:已取消就是取消了,再刷新也不会变。只有 UNKNOWN
|
|
674
|
+
// (厂商仍在对账)刷新才可能得到新结果。
|
|
675
|
+
retryable: status === 'UNKNOWN',
|
|
676
|
+
// 三态都给明细:确认中同样有车牌/停车时长/缴费时间可陈述,缺了它这张卡只剩一句话
|
|
677
|
+
details: receiptDetails(current),
|
|
678
|
+
};
|
|
679
|
+
return withCards(
|
|
680
|
+
facts,
|
|
681
|
+
'parking-payment-result',
|
|
682
|
+
// note 契约(W7):状态/金额前置(答话可直接转述,如「浙A12345 支付成功 · 12 元」)
|
|
683
|
+
`${current.plateNo} ${
|
|
684
|
+
status === 'PAID' ? '支付成功' : status === 'CANCELLED' ? '支付已取消' : '确认中'
|
|
685
|
+
} · ${formatCents(current.payableCents)}`,
|
|
686
|
+
);
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
// ===== 9. queryParkingPaymentDetail → parking-payment-records 卡 =====
|
|
691
|
+
const queryParkingPaymentDetail = createTool({
|
|
692
|
+
id: 'queryParkingPaymentDetail',
|
|
693
|
+
description:
|
|
694
|
+
'查询停车缴费订单详情(入场时间、出场时间、脱敏单号、开票状态)。recordRef 必须来自当前用户的停车缴费记录。',
|
|
695
|
+
inputSchema: coerce(
|
|
696
|
+
z.object({
|
|
697
|
+
recordRef: z
|
|
698
|
+
.string()
|
|
699
|
+
.min(1)
|
|
700
|
+
.max(128)
|
|
701
|
+
.describe('缴费记录中的不透明 recordRef'),
|
|
702
|
+
}),
|
|
703
|
+
),
|
|
704
|
+
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
705
|
+
const s = await serviceOf(execCtx, resolveParkingQueryPort);
|
|
706
|
+
// 会员门禁(属人读工具)
|
|
707
|
+
const gate = await parkingMembershipGate(opts.getCtx(), s.reqCtx as never, s.q, s.service);
|
|
708
|
+
if (gate)
|
|
709
|
+
return { found: false as const, message: gate.notice, ...(gate.card ? { cards: [gate.card] } : {}) };
|
|
710
|
+
const detail = await s.service.getPaymentRecordDetail(
|
|
711
|
+
s.q,
|
|
712
|
+
args.recordRef as string,
|
|
713
|
+
);
|
|
714
|
+
const settings = await s.service
|
|
715
|
+
.getInvoiceSettings(s.q)
|
|
716
|
+
.catch(() => ({ parkingInvoiceEnabled: false }));
|
|
717
|
+
const enriched = {
|
|
718
|
+
...detail,
|
|
719
|
+
invoiceEligible:
|
|
720
|
+
settings.parkingInvoiceEnabled &&
|
|
721
|
+
detail.orderCompleted === true &&
|
|
722
|
+
detail.invoiceIssued !== true,
|
|
723
|
+
};
|
|
724
|
+
const facts = {
|
|
725
|
+
items: [recordCardItem(enriched)],
|
|
726
|
+
total: 1,
|
|
727
|
+
hasMore: false,
|
|
728
|
+
caveats: [...PARKING_RECORDS_CAVEATS],
|
|
729
|
+
message: '已加载订单详情',
|
|
730
|
+
};
|
|
731
|
+
return withCards(
|
|
732
|
+
facts,
|
|
733
|
+
'parking-payment-records',
|
|
734
|
+
`${detail.plateNo} 停车缴费订单详情`,
|
|
735
|
+
);
|
|
736
|
+
},
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
// W2(2026-09-01):出卡工具创建点单点 wrap(description 追加预告知句)——
|
|
740
|
+
// 注册与 preTool 声明均使用 wrapped 实例;locateVehicle 无卡不 wrap。
|
|
741
|
+
return {
|
|
742
|
+
queryParkingFee: withCardEmissionHint(queryParkingFee, { actions: true }),
|
|
743
|
+
listVehicles: withCardEmissionHint(listVehicles, { actions: true }),
|
|
744
|
+
listPaymentRecords: withCardEmissionHint(listPaymentRecords),
|
|
745
|
+
queryParkingInfo: withCardEmissionHint(queryParkingInfo),
|
|
746
|
+
queryApplicableBenefits: withCardEmissionHint(queryApplicableBenefits),
|
|
747
|
+
locateVehicle,
|
|
748
|
+
listInvoiceableOrders: withCardEmissionHint(listInvoiceableOrders),
|
|
749
|
+
queryParkingPaymentStatus: withCardEmissionHint(queryParkingPaymentStatus, { actions: true }),
|
|
750
|
+
queryParkingPaymentDetail: withCardEmissionHint(queryParkingPaymentDetail),
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function paymentOwner(
|
|
755
|
+
q: ParkingQueryContext,
|
|
756
|
+
): { subjectId: string; mallId: string } | null {
|
|
757
|
+
return q.subjectId && q.scope.mallId
|
|
758
|
+
? { subjectId: q.subjectId, mallId: q.scope.mallId }
|
|
759
|
+
: null;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function recordCardItem(record: ParkingPaymentRecord) {
|
|
763
|
+
return {
|
|
764
|
+
recordRef: String(record.recordRef),
|
|
765
|
+
plateNo: record.plateNo,
|
|
766
|
+
amountText: formatCents(record.amountCents),
|
|
767
|
+
paidAtText: record.paidAt
|
|
768
|
+
? new Date(record.paidAt).toLocaleString('zh-CN')
|
|
769
|
+
: '-',
|
|
770
|
+
status: record.status,
|
|
771
|
+
...(record.statusText ? { statusText: record.statusText } : {}),
|
|
772
|
+
...(record.parkName ? { parkName: record.parkName } : {}),
|
|
773
|
+
...(record.plazaName ? { plazaName: record.plazaName } : {}),
|
|
774
|
+
...(record.entryAt
|
|
775
|
+
? { entryAtText: new Date(record.entryAt).toLocaleString('zh-CN') }
|
|
776
|
+
: {}),
|
|
777
|
+
...(record.exitAt
|
|
778
|
+
? { exitAtText: new Date(record.exitAt).toLocaleString('zh-CN') }
|
|
779
|
+
: {}),
|
|
780
|
+
...(record.payOrderNoMasked
|
|
781
|
+
? { payOrderNoMasked: record.payOrderNoMasked }
|
|
782
|
+
: {}),
|
|
783
|
+
...(record.orderCompleted !== undefined
|
|
784
|
+
? { orderCompleted: record.orderCompleted }
|
|
785
|
+
: {}),
|
|
786
|
+
...(record.invoiceEligible !== undefined
|
|
787
|
+
? { invoiceEligible: record.invoiceEligible }
|
|
788
|
+
: {}),
|
|
789
|
+
...(record.invoiceIssued !== undefined
|
|
790
|
+
? { invoiceIssued: record.invoiceIssued }
|
|
791
|
+
: {}),
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
export type {
|
|
796
|
+
ParkingQueryPort,
|
|
797
|
+
ParkingPaymentPort,
|
|
798
|
+
ParkingVehiclePort,
|
|
799
|
+
} from '@tbox.cn/app-contracts-mall';
|
|
800
|
+
|
|
801
|
+
// ===== W5 P0(2026-09-01):停车费问句四门 decide(纯函数,index.ts preTool 接线) =====
|
|
802
|
+
|
|
803
|
+
/** 费用意图(停车费/缴费/出场费/待支付/停车单) */
|
|
804
|
+
export const PARKING_FEE_INTENT_RE = /停车费|停车缴|缴费|出场费|待支付|停车单/;
|
|
805
|
+
/** 政策问句(怎么算/收费标准/计费规则)→ 走 queryParkingInfo(模型选 kind) */
|
|
806
|
+
export const PARKING_POLICY_QUESTION_RE = /怎么算|怎么收|收费标?准?|计费规则|收费规则/;
|
|
807
|
+
/** 历史时态(上个月/上次/历史/记录/流水)→ 走 listPaymentRecords */
|
|
808
|
+
export const PARKING_HISTORY_INTENT_RE = /上个月|上次|历史|记录|以前|之前|流水/;
|
|
809
|
+
/** 车牌点名(省份简称 + 发牌代字 + 5-6 位)→ 模型精确传参 */
|
|
810
|
+
export const PARKING_PLATE_MENTION_RE =
|
|
811
|
+
/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}/;
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* 停车费预执行四门门控(纯函数):
|
|
815
|
+
* 费用意图 ∧ ¬政策问句 ∧ ¬历史时态 ∧ ¬车牌点名 ∧ 非空文本 → run(零参——服务端自动扫描在场车);
|
|
816
|
+
* 其余 skip(防误触发兜底噪音;正则门语义见各 RE 注释)。
|
|
817
|
+
*/
|
|
818
|
+
export function decideParkingFeePreRun(
|
|
819
|
+
text: string | undefined,
|
|
820
|
+
): { decision: 'run'; args: {} } | { decision: 'skip'; reason: string } {
|
|
821
|
+
if (!text?.trim()) return { decision: 'skip', reason: '空文本' };
|
|
822
|
+
if (!PARKING_FEE_INTENT_RE.test(text)) return { decision: 'skip', reason: '非费用意图' };
|
|
823
|
+
if (PARKING_POLICY_QUESTION_RE.test(text))
|
|
824
|
+
return { decision: 'skip', reason: '政策问句(走 queryParkingInfo)' };
|
|
825
|
+
if (PARKING_HISTORY_INTENT_RE.test(text))
|
|
826
|
+
return { decision: 'skip', reason: '历史/时态意图(走 listPaymentRecords)' };
|
|
827
|
+
if (PARKING_PLATE_MENTION_RE.test(text))
|
|
828
|
+
return { decision: 'skip', reason: '点名车牌(模型精确传参)' };
|
|
829
|
+
return { decision: 'run', args: {} };
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// ===== 车辆问句预执行 decide(零工具直答兜底,2026-09-02) =====
|
|
833
|
+
|
|
834
|
+
/** 车牌点名(省份简称 + 发牌代字 + 5-6 位)→ 模型精确传参,不预执行 */
|
|
835
|
+
const VEHICLE_PLATE_MENTION_RE =
|
|
836
|
+
/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}/;
|
|
837
|
+
|
|
838
|
+
/** 车辆问句预执行门控:意图召回由 routing.terms 负责,decide 只排除车牌点名 */
|
|
839
|
+
export function decideListVehiclesPreRun(
|
|
840
|
+
text: string | undefined,
|
|
841
|
+
): { decision: 'run'; args: {} } | { decision: 'skip'; reason: string } {
|
|
842
|
+
if (!text?.trim()) return { decision: 'skip', reason: '空文本' };
|
|
843
|
+
if (VEHICLE_PLATE_MENTION_RE.test(text))
|
|
844
|
+
return { decision: 'skip', reason: '点名车牌(模型精确传参)' };
|
|
845
|
+
return { decision: 'run', args: {} };
|
|
846
|
+
}
|