@rine-kit/presentation 0.0.0-stage → 0.1.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/src/builders/pubg.d.ts +35 -0
- package/dist/src/builders/pubg.js +725 -0
- package/dist/src/contracts/owner.d.ts +20 -0
- package/dist/src/contracts/owner.js +1 -0
- package/dist/src/contracts/pubg.d.ts +200 -0
- package/dist/src/contracts/pubg.js +1 -0
- package/dist/src/contracts/session-review.d.ts +72 -0
- package/dist/src/contracts/session-review.js +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.js +19 -0
- package/dist/src/pubg-registry.d.ts +21 -0
- package/dist/src/pubg-registry.js +123 -0
- package/dist/src/renderers/daily-review.d.ts +22 -0
- package/dist/src/renderers/daily-review.js +149 -0
- package/dist/src/renderers/owner.d.ts +6 -0
- package/dist/src/renderers/owner.js +35 -0
- package/dist/src/renderers/pubg.d.ts +22 -0
- package/dist/src/renderers/pubg.js +603 -0
- package/dist/src/renderers/session-review.d.ts +15 -0
- package/dist/src/renderers/session-review.js +187 -0
- package/dist/src/reply-check.d.ts +3 -0
- package/dist/src/reply-check.js +44 -0
- package/dist/src/reply-guides.d.ts +10 -0
- package/dist/src/reply-guides.js +64 -0
- package/dist/src/time/format.d.ts +16 -0
- package/dist/src/time/format.js +63 -0
- package/dist/src/validation/session-review.d.ts +3 -0
- package/dist/src/validation/session-review.js +136 -0
- package/dist/src/validation/validate.d.ts +18 -0
- package/dist/src/validation/validate.js +736 -0
- package/dist/src/worldline/adapter.d.ts +3 -0
- package/dist/src/worldline/adapter.js +47 -0
- package/dist/src/worldline/contracts.d.ts +44 -0
- package/dist/src/worldline/contracts.js +40 -0
- package/dist/src/worldline/policy.d.ts +2 -0
- package/dist/src/worldline/policy.js +31 -0
- package/dist/src/worldline/renderer.d.ts +3 -0
- package/dist/src/worldline/renderer.js +5 -0
- package/dist/src/worldline/vocabulary.d.ts +2 -0
- package/dist/src/worldline/vocabulary.js +1 -0
- package/package.json +33 -3
- package/README.md +0 -3
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { assertValid } from '../validation/validate.js';
|
|
2
|
+
import { validateSessionReviewPresentation } from '../validation/session-review.js';
|
|
3
|
+
/** Target size for a group-chat message: about one and a half phone screens. */
|
|
4
|
+
export const SESSION_REVIEW_MAX_CHARS = 1000;
|
|
5
|
+
const STRIP_MAX = 12;
|
|
6
|
+
const MAP_NAMES = {
|
|
7
|
+
Baltic_Main: '艾伦格',
|
|
8
|
+
Erangel_Main: '艾伦格',
|
|
9
|
+
Desert_Main: '米拉玛',
|
|
10
|
+
Tiger_Main: '泰戈',
|
|
11
|
+
Neon_Main: '荣都',
|
|
12
|
+
Kiki_Main: '帝斯顿',
|
|
13
|
+
Savage_Main: '萨诺',
|
|
14
|
+
DihorOtok_Main: '维寒迪',
|
|
15
|
+
Chimera_Main: '帕拉莫',
|
|
16
|
+
Summerland_Main: '卡拉金',
|
|
17
|
+
Heaven_Main: '哈文',
|
|
18
|
+
};
|
|
19
|
+
export function sessionMapName(mapName) {
|
|
20
|
+
return MAP_NAMES[mapName] ?? (mapName.replace(/_Main$/u, '') || '未知地图');
|
|
21
|
+
}
|
|
22
|
+
function clock(value, timezone) {
|
|
23
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {
|
|
24
|
+
timeZone: timezone,
|
|
25
|
+
month: '2-digit',
|
|
26
|
+
day: '2-digit',
|
|
27
|
+
hour: '2-digit',
|
|
28
|
+
minute: '2-digit',
|
|
29
|
+
hourCycle: 'h23',
|
|
30
|
+
})
|
|
31
|
+
.formatToParts(new Date(value))
|
|
32
|
+
.map((part) => [part.type, part.value]));
|
|
33
|
+
return { date: `${parts.month}/${parts.day}`, time: `${parts.hour}:${parts.minute}` };
|
|
34
|
+
}
|
|
35
|
+
function placement(rank) {
|
|
36
|
+
if (rank === null)
|
|
37
|
+
return '#?';
|
|
38
|
+
return rank === 1 ? '🏆' : `#${rank}`;
|
|
39
|
+
}
|
|
40
|
+
export { placement as sessionPlacement, strip as sessionPlacementStrip };
|
|
41
|
+
function strip(placements) {
|
|
42
|
+
if (placements.length <= STRIP_MAX)
|
|
43
|
+
return placements.map(placement).join(' ');
|
|
44
|
+
const half = STRIP_MAX / 2;
|
|
45
|
+
return [
|
|
46
|
+
...placements.slice(0, half).map(placement),
|
|
47
|
+
'…',
|
|
48
|
+
...placements.slice(-half).map(placement),
|
|
49
|
+
].join(' ');
|
|
50
|
+
}
|
|
51
|
+
function one(value) {
|
|
52
|
+
return value === null ? '?' : value.toFixed(1);
|
|
53
|
+
}
|
|
54
|
+
function memberLine(member, showMatches, withTags) {
|
|
55
|
+
const tags = withTags
|
|
56
|
+
? member.tags
|
|
57
|
+
.slice(0, 2)
|
|
58
|
+
.map((tag) => tag === 'top_damage'
|
|
59
|
+
? ' ⭐'
|
|
60
|
+
: tag === 'early_outs'
|
|
61
|
+
? ` ⚠ 早出局 ${member.earlyOuts} 次`
|
|
62
|
+
: ` 🩹 救援 ${member.revives}`)
|
|
63
|
+
.join('')
|
|
64
|
+
: '';
|
|
65
|
+
const games = showMatches ? ` · ${member.matches} 场` : '';
|
|
66
|
+
return `${member.name} 击倒 ${member.knocks} · 淘汰 ${member.kills} · 伤害 ${Math.round(member.damagePerMatch)}/场${games}${tags}`;
|
|
67
|
+
}
|
|
68
|
+
function minute(seconds) {
|
|
69
|
+
return `第 ${Math.max(1, Math.ceil(seconds / 60))} 分钟`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Renders the review as WhatsApp text. When it is too long, whole sections are dropped from the least important up;
|
|
73
|
+
* the title, verdict, placements and the link always stay and nothing is cut mid-sentence.
|
|
74
|
+
*/
|
|
75
|
+
export function renderSessionReview(presentation, options = {}) {
|
|
76
|
+
const review = assertValid(validateSessionReviewPresentation(presentation));
|
|
77
|
+
const maxChars = options.maxChars ?? SESSION_REVIEW_MAX_CHARS;
|
|
78
|
+
const start = clock(review.startAt, review.timezone);
|
|
79
|
+
const end = clock(review.endAt, review.timezone);
|
|
80
|
+
const window = start.date === end.date
|
|
81
|
+
? `${start.date} ${start.time}–${end.time}`
|
|
82
|
+
: `${start.date} ${start.time}–${end.date} ${end.time}`;
|
|
83
|
+
const single = review.matchCount === 1;
|
|
84
|
+
const sameMatchCounts = new Set(review.members.map((member) => member.matches)).size <= 1;
|
|
85
|
+
const maps = review.maps
|
|
86
|
+
.map((map) => map.count > 1 ? `${sessionMapName(map.mapName)}×${map.count}` : sessionMapName(map.mapName))
|
|
87
|
+
.join(' ');
|
|
88
|
+
const build = (dropped, findingLimit, memberTags) => {
|
|
89
|
+
const sections = [];
|
|
90
|
+
sections.push({
|
|
91
|
+
lines: [
|
|
92
|
+
single ? `*🎮 单局复盘 · ${window}*` : `*🎮 时段复盘 · ${window}*`,
|
|
93
|
+
`${review.matchCount} 场排位 · ${maps}`,
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
sections.push({ lines: [`*一句话:${review.headline}*`] });
|
|
97
|
+
if (single) {
|
|
98
|
+
const rank = review.placements[0] ?? null;
|
|
99
|
+
sections.push({
|
|
100
|
+
lines: [
|
|
101
|
+
`*名次* ${placement(rank)} · 击倒 ${review.summary.teamKnocks} · 团队伤害 ${Math.round(review.summary.avgTeamDamage)}`,
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
if (review.timeline?.length)
|
|
105
|
+
sections.push({
|
|
106
|
+
drop: 3,
|
|
107
|
+
lines: [
|
|
108
|
+
'*过程*',
|
|
109
|
+
...review.timeline.slice(0, 3).map((item) => `${minute(item.atSeconds)} ${item.text}`),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const baseline = review.summary.baselineAvgPlacement === null
|
|
115
|
+
? ''
|
|
116
|
+
: `(你们平时 ${one(review.summary.baselineAvgPlacement)})`;
|
|
117
|
+
sections.push({
|
|
118
|
+
lines: [
|
|
119
|
+
`*名次* ${strip(review.placements)}`,
|
|
120
|
+
`场均名次 ${one(review.summary.avgPlacement)}${baseline}`,
|
|
121
|
+
`击倒 ${review.summary.teamKnocks} · 场均团队伤害 ${Math.round(review.summary.avgTeamDamage)} · 吃鸡 ${review.summary.wins} · 前十 ${review.summary.top10}`,
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const findings = review.findings.slice(0, single ? Math.min(1, findingLimit) : findingLimit);
|
|
126
|
+
sections.push({
|
|
127
|
+
lines: findings.length
|
|
128
|
+
? [
|
|
129
|
+
'*结论*',
|
|
130
|
+
...findings.map((finding, index) => single ? finding.text : `${index + 1}. ${finding.text}`),
|
|
131
|
+
]
|
|
132
|
+
: ['*结论*', '各项都在你们平时的正常波动范围内,没有值得单独拎出来的问题。'],
|
|
133
|
+
});
|
|
134
|
+
if (!single && review.members.length) {
|
|
135
|
+
sections.push({
|
|
136
|
+
drop: 4,
|
|
137
|
+
lines: [
|
|
138
|
+
'*队员*',
|
|
139
|
+
...review.members.map((member) => memberLine(member, !sameMatchCounts, memberTags)),
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (!single && review.bestMatch)
|
|
144
|
+
sections.push({
|
|
145
|
+
drop: 2,
|
|
146
|
+
lines: [
|
|
147
|
+
`*最好一局* ${placement(review.bestMatch.rank)} ${sessionMapName(review.bestMatch.mapName)} · ${review.bestMatch.text}`,
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
if (!single && review.worstMatch)
|
|
151
|
+
sections.push({
|
|
152
|
+
drop: 1,
|
|
153
|
+
lines: [
|
|
154
|
+
`*最差一局* ${placement(review.worstMatch.rank)} ${sessionMapName(review.worstMatch.mapName)} · ${review.worstMatch.text}`,
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
if (review.suggestion)
|
|
158
|
+
sections.push({ drop: 5, lines: [`*下次试试* ${review.suggestion}`] });
|
|
159
|
+
const coverage = review.coverage.telemetry === review.coverage.total
|
|
160
|
+
? `📎 ${review.coverage.total}/${review.coverage.total} 场有完整遥测`
|
|
161
|
+
: `📎 ${review.coverage.telemetry}/${review.coverage.total} 场有完整遥测,其余只按基础战绩`;
|
|
162
|
+
sections.push({ lines: review.link ? [coverage, `🔗 ${review.link}`] : [coverage] });
|
|
163
|
+
return sections
|
|
164
|
+
.filter((section) => section.drop === undefined || !dropped.has(section.drop))
|
|
165
|
+
.map((section) => section.lines.join('\n'))
|
|
166
|
+
.join('\n\n');
|
|
167
|
+
};
|
|
168
|
+
// Trimming ladder: worst match → best match → member tags → findings down to two → timeline → members → suggestion.
|
|
169
|
+
const steps = [
|
|
170
|
+
{ dropped: [], findings: 3, tags: true },
|
|
171
|
+
{ dropped: [1], findings: 3, tags: true },
|
|
172
|
+
{ dropped: [1, 2], findings: 3, tags: true },
|
|
173
|
+
{ dropped: [1, 2], findings: 3, tags: false },
|
|
174
|
+
{ dropped: [1, 2], findings: 2, tags: false },
|
|
175
|
+
{ dropped: [1, 2, 3], findings: 2, tags: false },
|
|
176
|
+
{ dropped: [1, 2, 3, 4], findings: 2, tags: false },
|
|
177
|
+
{ dropped: [1, 2, 3, 4, 5], findings: 2, tags: false },
|
|
178
|
+
{ dropped: [1, 2, 3, 4, 5], findings: 1, tags: false },
|
|
179
|
+
];
|
|
180
|
+
let rendered = '';
|
|
181
|
+
for (const step of steps) {
|
|
182
|
+
rendered = build(new Set(step.dropped), step.findings, step.tags);
|
|
183
|
+
if (rendered.length <= maxChars)
|
|
184
|
+
return rendered;
|
|
185
|
+
}
|
|
186
|
+
return rendered;
|
|
187
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { assignStatTitles, formatMetricNumber } from './renderers/pubg.js';
|
|
2
|
+
/*
|
|
3
|
+
* Did a retold reply keep the facts its block must carry? Names are not checked (the agent swaps account names for
|
|
4
|
+
* 称呼); the numbers and titles that identify each card or direction are. Only the layouts whose guide demands the
|
|
5
|
+
* whole block (战绩 cards, the 队内误伤账本) are checked; narrower answers are left alone.
|
|
6
|
+
*/
|
|
7
|
+
function numberForms(key, value) {
|
|
8
|
+
const shown = formatMetricNumber(key, value);
|
|
9
|
+
// "2743.0" may be written "2743"; any other rounding is a changed number.
|
|
10
|
+
return shown.endsWith('.0') ? [shown, shown.slice(0, -2)] : [shown];
|
|
11
|
+
}
|
|
12
|
+
function present(reply, forms) {
|
|
13
|
+
return forms.some((form) => new RegExp(`(?<![\\d.])${form.replace('.', '\\.')}(?![\\d])`, 'u').test(reply));
|
|
14
|
+
}
|
|
15
|
+
/** Short labels of the facts the reply dropped; empty when it kept them all or the layout is not checked. */
|
|
16
|
+
export function missingReplyFacts(presentation, reply) {
|
|
17
|
+
if (presentation.status !== 'ok' && presentation.status !== 'partial')
|
|
18
|
+
return [];
|
|
19
|
+
const missing = [];
|
|
20
|
+
if (presentation.type === 'pubg_stats') {
|
|
21
|
+
const titles = assignStatTitles(presentation.rows);
|
|
22
|
+
presentation.rows.forEach((row, index) => {
|
|
23
|
+
for (const key of ['kd', 'damage']) {
|
|
24
|
+
const value = row.values[key];
|
|
25
|
+
if (typeof value === 'number' &&
|
|
26
|
+
Number.isFinite(value) &&
|
|
27
|
+
!present(reply, numberForms(key, value)))
|
|
28
|
+
missing.push(`${row.label} 的${key === 'kd' ? ' KD' : '伤害'} ${formatMetricNumber(key, value)}`);
|
|
29
|
+
}
|
|
30
|
+
for (const title of titles.get(index) ?? [])
|
|
31
|
+
if (!reply.includes(title))
|
|
32
|
+
missing.push(`${row.label} 的称号「${title}」`);
|
|
33
|
+
});
|
|
34
|
+
if (presentation.rows.length >= 2 && !reply.includes('团队合计'))
|
|
35
|
+
missing.push('团队合计');
|
|
36
|
+
}
|
|
37
|
+
else if (presentation.type === 'pubg_team_damage') {
|
|
38
|
+
for (const direction of presentation.directions) {
|
|
39
|
+
if (direction.damage !== null && !present(reply, numberForms('damage', direction.damage)))
|
|
40
|
+
missing.push(`${direction.actor} → ${direction.victim} 的 ${formatMetricNumber('damage', direction.damage)} 伤害`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return missing;
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PubgPresentation } from './contracts/pubg.js';
|
|
2
|
+
export declare const STATS_REPLY_GUIDE: string;
|
|
3
|
+
export declare const TEAM_DAMAGE_REPLY_GUIDE: string;
|
|
4
|
+
export declare const MATCH_LIST_REPLY_GUIDE: string;
|
|
5
|
+
export declare const GENERAL_REPLY_GUIDE: string;
|
|
6
|
+
export declare const NO_MATCHES_REPLY_GUIDE = "\u6CA1\u6709\u627E\u5230\u7B26\u5408\u6761\u4EF6\u7684\u6BD4\u8D5B\uFF1A\u7528\u4EBA\u8BBE\u53E3\u543B\u5982\u5B9E\u8BF4\u660E\u67E5\u8BE2\u7684\u65F6\u95F4\u8303\u56F4\u91CC\u6CA1\u6709\u5BF9\u5C40\uFF08\u53EF\u4EE5\u5410\u69FD\u4E00\u53E5\uFF09\uFF0C\u4E0D\u8981\u7F16\u4EFB\u4F55\u6570\u5B57\uFF0C\u4E5F\u4E0D\u8981\u62FF\u4EE5\u524D\u7684\u6218\u7EE9\u4EE3\u66FF\u3002";
|
|
7
|
+
export declare const PARTIAL_REPLY_GUIDE = "\u6570\u636E\u4E0D\u5B8C\u6574\uFF1A\u7167\u5E38\u5199\u56DE\u590D\uFF0C\u4F46\u8981\u70B9\u660E\u54EA\u4E9B\u90E8\u5206\u7F3A\u5931\u6216\u672A\u77E5\uFF1B\u672A\u77E5\u4E0D\u662F 0\uFF0C\u4E0D\u8981\u8865\u5168\u6216\u731C\u6D4B\u3002";
|
|
8
|
+
export declare const ERROR_REPLY_GUIDE = "\u8FD9\u6B21\u67E5\u8BE2\u5931\u8D25\uFF1A\u7528\u4E00\u4E24\u53E5\u5982\u5B9E\u8BF4\u660E\u6CA1\u67E5\u5230\u3001\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF0C\u4E0D\u8981\u7528\u804A\u5929\u8BB0\u5F55\u91CC\u7684\u65E7\u6570\u5B57\u56DE\u7B54\u3002";
|
|
9
|
+
/** The guide for a result, or undefined when the result needs none (internal tools, plain status messages). */
|
|
10
|
+
export declare function pubgReplyGuide(presentation: PubgPresentation): string | undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How an agent should retell each kind of PUBG answer, shared by every product that hands a PUBG result to a model.
|
|
3
|
+
* The guide travels inside the tool result, next to the facts, because a lazily loaded skill is not reliably read.
|
|
4
|
+
* Guides describe shape only: every number comes from displayText, and voice/persona stay with each product's own
|
|
5
|
+
* prompt. A product may append its own worked example.
|
|
6
|
+
*/
|
|
7
|
+
export const STATS_REPLY_GUIDE = [
|
|
8
|
+
'这是一份战绩查询结果。回复就是一份完整战报,按下面的结构写,不要压缩成一行一人的短列表:',
|
|
9
|
+
'1. 开场一两句人设口吻:按称呼名册点名提问的人,评论这段时间的局数、吃鸡或最亮眼的数字。',
|
|
10
|
+
'2. 原样保留 displayText 的标题行(🏆 …)。',
|
|
11
|
+
'3. 每个队员一张卡,顺序和勋章(🥇🥈🥉🎖️,按 K/D 排)与 displayText 一致,不要自己重排:',
|
|
12
|
+
' - 名字行:可在名字前加一个贴切的外号,名字换成名册里的称呼,括号保留 PUBG 账号。',
|
|
13
|
+
' - 「• 出战 N 局:…」和「• 个人数据:…」两行逐字照抄,数字、称号(全队助攻王 / 全队伤害第一 / 破点王 / 全队救援王)和 **加粗** 一个不能少。',
|
|
14
|
+
' - 再加一行「• AI 锐评:…」,一两句毒舌或夸奖,只引用这个人卡片上的真实数字。',
|
|
15
|
+
'4. 「团队合计:…」一行原样保留并加粗。',
|
|
16
|
+
'5. 收尾一两句吐槽,点名谁 carry、谁死得最多或谁拉人最多,落在称呼上。',
|
|
17
|
+
'6. displayText 最后如果有 🔗 分享链接,原样放在回复最后一行。',
|
|
18
|
+
'不得编造数字、外号以外的事实或 displayText 里没有的称号。',
|
|
19
|
+
].join('\n');
|
|
20
|
+
export const TEAM_DAMAGE_REPLY_GUIDE = [
|
|
21
|
+
'这是一份队内误伤(队友互相伤害)账本。回复写成完整的「对账」战报,不要压缩成几行短列表:',
|
|
22
|
+
'1. 开场一两句人设口吻:点名提问的人,接上他刚说的话或当天的梗。',
|
|
23
|
+
'2. 总账:保留 displayText 的总误伤、总命中和括号里的分类(飞踢 / 重拳 / 载具撞击 / 走火)。',
|
|
24
|
+
'3. 「互相伤害明细」逐条保留每个方向:名字换成名册称呼、括号保留 PUBG 账号,可以给方向起一个小标题;',
|
|
25
|
+
' 每条下面保留「总输出:N 次命中,造成 X 伤害(分类)」,再补一句只引用这条数字的吐槽。',
|
|
26
|
+
' 两个人互相打时,算出两人对攻合计和占全队误伤的比例(只用 displayText 的数字计算)。',
|
|
27
|
+
'4. 有「名场面」时原样保留每一局的局号、地图、名次和每个方向的次数与伤害,再加一句画面感的描述(不要编位置、时机等数据里没有的细节)。',
|
|
28
|
+
'5. 有清白名单时点名表扬一句(0 次主动队内输出)。',
|
|
29
|
+
'6. 总结两三句:谁是内耗核心、谁挨打最多,落在称呼上收尾。',
|
|
30
|
+
'没有任何方向时,直接说这段时间没有队内误伤记录,不要编。数据不完整时说明哪些未知,不要把未知当 0。',
|
|
31
|
+
].join('\n');
|
|
32
|
+
export const MATCH_LIST_REPLY_GUIDE = [
|
|
33
|
+
'这是一份对局列表。回复保留 displayText 里每一局的序号、时间、地图、名次和每个人的击杀 / 伤害,名字换成名册称呼;',
|
|
34
|
+
'开场一两句点名提问的人,结尾一两句点评(哪局最好、哪局最惨、谁最稳),只引用列表里的数字。',
|
|
35
|
+
'如果用户是在问「只看四排 / 去掉双排后的 KD」这类问题,先说明列表的筛选条件,再按列表里的数字逐人算出结果,写清算法(例如 KD = 击杀 ÷ 死亡),不要编死亡数之类列表里没有的数字。',
|
|
36
|
+
].join('\n');
|
|
37
|
+
export const GENERAL_REPLY_GUIDE = [
|
|
38
|
+
'回复以 displayText 为事实块:保留其中所有数字、名次、称号和链接,名字换成名册称呼;',
|
|
39
|
+
'前后加人设口吻的开场和点评,点评只引用 displayText 里的真实数字,不要把事实块压缩成一两句。',
|
|
40
|
+
].join('\n');
|
|
41
|
+
export const NO_MATCHES_REPLY_GUIDE = '没有找到符合条件的比赛:用人设口吻如实说明查询的时间范围里没有对局(可以吐槽一句),不要编任何数字,也不要拿以前的战绩代替。';
|
|
42
|
+
export const PARTIAL_REPLY_GUIDE = '数据不完整:照常写回复,但要点明哪些部分缺失或未知;未知不是 0,不要补全或猜测。';
|
|
43
|
+
export const ERROR_REPLY_GUIDE = '这次查询失败:用一两句如实说明没查到、请稍后再试,不要用聊天记录里的旧数字回答。';
|
|
44
|
+
/** The guide for a result, or undefined when the result needs none (internal tools, plain status messages). */
|
|
45
|
+
export function pubgReplyGuide(presentation) {
|
|
46
|
+
if (presentation.status === 'error')
|
|
47
|
+
return ERROR_REPLY_GUIDE;
|
|
48
|
+
if (presentation.status === 'no_matches')
|
|
49
|
+
return NO_MATCHES_REPLY_GUIDE;
|
|
50
|
+
const guide = presentation.type === 'pubg_stats'
|
|
51
|
+
? presentation.rows.length
|
|
52
|
+
? STATS_REPLY_GUIDE
|
|
53
|
+
: undefined
|
|
54
|
+
: presentation.type === 'pubg_team_damage'
|
|
55
|
+
? TEAM_DAMAGE_REPLY_GUIDE
|
|
56
|
+
: presentation.type === 'pubg_match_list'
|
|
57
|
+
? MATCH_LIST_REPLY_GUIDE
|
|
58
|
+
: presentation.type === 'pubg_status'
|
|
59
|
+
? undefined
|
|
60
|
+
: GENERAL_REPLY_GUIDE;
|
|
61
|
+
if (!guide)
|
|
62
|
+
return undefined;
|
|
63
|
+
return presentation.status === 'partial' ? `${guide}\n${PARTIAL_REPLY_GUIDE}` : guide;
|
|
64
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DEFAULT_DISPLAY_TIMEZONE = "Asia/Shanghai";
|
|
2
|
+
export interface DisplayTimeOptions {
|
|
3
|
+
timezone?: string;
|
|
4
|
+
now?: Date | string;
|
|
5
|
+
includeSeconds?: boolean;
|
|
6
|
+
forceDate?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Format a real instant for a user-facing display. Same-local-date values use
|
|
10
|
+
* HH:mm by default; values on another local date include YYYY-MM-DD HH:mm.
|
|
11
|
+
* The implementation timezone is intentionally never appended to the text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatDisplayTime(value: Date | string | null | undefined, options?: DisplayTimeOptions): string | null;
|
|
14
|
+
export declare function formatDisplayDate(value: Date | string | null | undefined, timezone?: string): string | null;
|
|
15
|
+
export declare function formatDisplayRange(from: Date | string | null | undefined, to: Date | string | null | undefined, options?: DisplayTimeOptions): string;
|
|
16
|
+
export declare function containsInternalTimeTerms(value: string): boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const DEFAULT_DISPLAY_TIMEZONE = 'Asia/Shanghai';
|
|
2
|
+
function parts(value, timezone) {
|
|
3
|
+
const formatted = new Intl.DateTimeFormat('en-US', {
|
|
4
|
+
timeZone: timezone,
|
|
5
|
+
year: 'numeric',
|
|
6
|
+
month: '2-digit',
|
|
7
|
+
day: '2-digit',
|
|
8
|
+
hour: '2-digit',
|
|
9
|
+
minute: '2-digit',
|
|
10
|
+
second: '2-digit',
|
|
11
|
+
hourCycle: 'h23',
|
|
12
|
+
}).formatToParts(value);
|
|
13
|
+
const values = Object.fromEntries(formatted.filter((item) => item.type !== 'literal').map((item) => [item.type, item.value]));
|
|
14
|
+
return {
|
|
15
|
+
year: String(values.year),
|
|
16
|
+
month: String(values.month),
|
|
17
|
+
day: String(values.day),
|
|
18
|
+
hour: String(values.hour),
|
|
19
|
+
minute: String(values.minute),
|
|
20
|
+
second: String(values.second),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function date(value, timezone) {
|
|
24
|
+
const local = parts(value, timezone);
|
|
25
|
+
return `${local.year}-${local.month}-${local.day}`;
|
|
26
|
+
}
|
|
27
|
+
function parse(value) {
|
|
28
|
+
if (value instanceof Date)
|
|
29
|
+
return Number.isFinite(value.getTime()) ? value : null;
|
|
30
|
+
if (typeof value !== 'string' || !value.trim())
|
|
31
|
+
return null;
|
|
32
|
+
const parsed = new Date(value);
|
|
33
|
+
return Number.isFinite(parsed.getTime()) ? parsed : null;
|
|
34
|
+
}
|
|
35
|
+
function referenceNow(value) {
|
|
36
|
+
return parse(value) ?? new Date();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Format a real instant for a user-facing display. Same-local-date values use
|
|
40
|
+
* HH:mm by default; values on another local date include YYYY-MM-DD HH:mm.
|
|
41
|
+
* The implementation timezone is intentionally never appended to the text.
|
|
42
|
+
*/
|
|
43
|
+
export function formatDisplayTime(value, options = {}) {
|
|
44
|
+
const parsed = parse(value);
|
|
45
|
+
if (!parsed)
|
|
46
|
+
return null;
|
|
47
|
+
const timezone = options.timezone ?? DEFAULT_DISPLAY_TIMEZONE;
|
|
48
|
+
const local = parts(parsed, timezone);
|
|
49
|
+
const sameDay = date(parsed, timezone) === date(referenceNow(options.now), timezone);
|
|
50
|
+
const withDate = options.forceDate === true || !sameDay;
|
|
51
|
+
const clock = `${local.hour}:${local.minute}${options.includeSeconds ? `:${local.second}` : ''}`;
|
|
52
|
+
return withDate ? `${local.year}-${local.month}-${local.day} ${clock}` : clock;
|
|
53
|
+
}
|
|
54
|
+
export function formatDisplayDate(value, timezone = DEFAULT_DISPLAY_TIMEZONE) {
|
|
55
|
+
const parsed = parse(value);
|
|
56
|
+
return parsed ? date(parsed, timezone) : null;
|
|
57
|
+
}
|
|
58
|
+
export function formatDisplayRange(from, to, options = {}) {
|
|
59
|
+
return `${formatDisplayTime(from, { ...options, forceDate: true }) ?? '未知'} 至 ${formatDisplayTime(to, { ...options, forceDate: true }) ?? '未知'}`;
|
|
60
|
+
}
|
|
61
|
+
export function containsInternalTimeTerms(value) {
|
|
62
|
+
return /Asia\/Shanghai|UTC\+?08(?::00)?|自然日|业务日/u.test(value);
|
|
63
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const TONES = ['good', 'bad', 'neutral'];
|
|
2
|
+
const CONFIDENCES = ['clear', 'observation'];
|
|
3
|
+
const TAGS = ['top_damage', 'early_outs', 'medic'];
|
|
4
|
+
function text(value, path, errors, required = true) {
|
|
5
|
+
if (typeof value === 'string' && value.trim())
|
|
6
|
+
return value;
|
|
7
|
+
if (required || value !== undefined)
|
|
8
|
+
errors.push(`${path} must be a non-empty string`);
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
function finite(value, path, errors, nullable = false) {
|
|
12
|
+
if (nullable && value === null)
|
|
13
|
+
return null;
|
|
14
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
15
|
+
return value;
|
|
16
|
+
errors.push(`${path} must be a finite number${nullable ? ' or null' : ''}`);
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
function count(value, path, errors) {
|
|
20
|
+
const parsed = finite(value, path, errors);
|
|
21
|
+
if (typeof parsed === 'number' && (parsed < 0 || !Number.isInteger(parsed)))
|
|
22
|
+
errors.push(`${path} must be a non-negative integer`);
|
|
23
|
+
return parsed ?? undefined;
|
|
24
|
+
}
|
|
25
|
+
function instant(value, path, errors) {
|
|
26
|
+
const parsed = text(value, path, errors);
|
|
27
|
+
if (parsed && !Number.isFinite(Date.parse(parsed)))
|
|
28
|
+
errors.push(`${path} must be an ISO timestamp`);
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
function record(value, path, errors) {
|
|
32
|
+
if (value && typeof value === 'object' && !Array.isArray(value))
|
|
33
|
+
return value;
|
|
34
|
+
errors.push(`${path} must be an object`);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function list(value, path, errors) {
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
return value;
|
|
40
|
+
errors.push(`${path} must be an array`);
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
function matchNote(value, path, errors) {
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
const row = record(value, path, errors);
|
|
47
|
+
if (!row)
|
|
48
|
+
return undefined;
|
|
49
|
+
text(row.matchId, `${path}.matchId`, errors);
|
|
50
|
+
finite(row.rank, `${path}.rank`, errors, true);
|
|
51
|
+
text(row.mapName, `${path}.mapName`, errors);
|
|
52
|
+
text(row.text, `${path}.text`, errors);
|
|
53
|
+
return row;
|
|
54
|
+
}
|
|
55
|
+
export function validateSessionReviewPresentation(value) {
|
|
56
|
+
const errors = [];
|
|
57
|
+
const row = record(value, 'presentation', errors);
|
|
58
|
+
if (!row)
|
|
59
|
+
return { valid: false, errors };
|
|
60
|
+
if (row.type !== 'pubg_session_review')
|
|
61
|
+
errors.push('type must be pubg_session_review');
|
|
62
|
+
if (row.version !== 1)
|
|
63
|
+
errors.push('version must be 1');
|
|
64
|
+
for (const key of ['sessionKey', 'squadLabel', 'timezone', 'headline'])
|
|
65
|
+
text(row[key], key, errors);
|
|
66
|
+
for (const key of ['startAt', 'endAt', 'generatedAt'])
|
|
67
|
+
instant(row[key], key, errors);
|
|
68
|
+
const matchCount = count(row.matchCount, 'matchCount', errors);
|
|
69
|
+
if (matchCount === 0)
|
|
70
|
+
errors.push('matchCount must be at least 1');
|
|
71
|
+
list(row.maps, 'maps', errors).forEach((item, index) => {
|
|
72
|
+
const map = record(item, `maps[${index}]`, errors);
|
|
73
|
+
if (!map)
|
|
74
|
+
return;
|
|
75
|
+
text(map.mapName, `maps[${index}].mapName`, errors);
|
|
76
|
+
count(map.count, `maps[${index}].count`, errors);
|
|
77
|
+
});
|
|
78
|
+
const placements = list(row.placements, 'placements', errors);
|
|
79
|
+
placements.forEach((item, index) => finite(item, `placements[${index}]`, errors, true));
|
|
80
|
+
if (matchCount !== undefined && placements.length !== matchCount)
|
|
81
|
+
errors.push('placements must have one entry per match');
|
|
82
|
+
const summary = record(row.summary, 'summary', errors);
|
|
83
|
+
if (summary) {
|
|
84
|
+
finite(summary.avgPlacement, 'summary.avgPlacement', errors, true);
|
|
85
|
+
finite(summary.baselineAvgPlacement, 'summary.baselineAvgPlacement', errors, true);
|
|
86
|
+
for (const key of ['wins', 'top10', 'teamKnocks'])
|
|
87
|
+
count(summary[key], `summary.${key}`, errors);
|
|
88
|
+
finite(summary.avgTeamDamage, 'summary.avgTeamDamage', errors);
|
|
89
|
+
}
|
|
90
|
+
list(row.findings, 'findings', errors).forEach((item, index) => {
|
|
91
|
+
const finding = record(item, `findings[${index}]`, errors);
|
|
92
|
+
if (!finding)
|
|
93
|
+
return;
|
|
94
|
+
text(finding.metric, `findings[${index}].metric`, errors);
|
|
95
|
+
text(finding.text, `findings[${index}].text`, errors);
|
|
96
|
+
if (!TONES.includes(finding.tone))
|
|
97
|
+
errors.push(`findings[${index}].tone is invalid`);
|
|
98
|
+
if (!CONFIDENCES.includes(finding.confidence))
|
|
99
|
+
errors.push(`findings[${index}].confidence is invalid`);
|
|
100
|
+
});
|
|
101
|
+
list(row.members, 'members', errors).forEach((item, index) => {
|
|
102
|
+
const member = record(item, `members[${index}]`, errors);
|
|
103
|
+
if (!member)
|
|
104
|
+
return;
|
|
105
|
+
text(member.name, `members[${index}].name`, errors);
|
|
106
|
+
for (const key of ['matches', 'kills', 'knocks', 'earlyOuts', 'revives'])
|
|
107
|
+
count(member[key], `members[${index}].${key}`, errors);
|
|
108
|
+
finite(member.damagePerMatch, `members[${index}].damagePerMatch`, errors);
|
|
109
|
+
const tags = list(member.tags, `members[${index}].tags`, errors);
|
|
110
|
+
if (tags.some((tag) => !TAGS.includes(tag)))
|
|
111
|
+
errors.push(`members[${index}].tags has an unknown tag`);
|
|
112
|
+
});
|
|
113
|
+
matchNote(row.bestMatch, 'bestMatch', errors);
|
|
114
|
+
matchNote(row.worstMatch, 'worstMatch', errors);
|
|
115
|
+
if (row.timeline !== undefined) {
|
|
116
|
+
list(row.timeline, 'timeline', errors).forEach((item, index) => {
|
|
117
|
+
const moment = record(item, `timeline[${index}]`, errors);
|
|
118
|
+
if (!moment)
|
|
119
|
+
return;
|
|
120
|
+
finite(moment.atSeconds, `timeline[${index}].atSeconds`, errors);
|
|
121
|
+
text(moment.text, `timeline[${index}].text`, errors);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
text(row.suggestion, 'suggestion', errors, false);
|
|
125
|
+
text(row.link, 'link', errors, false);
|
|
126
|
+
const coverage = record(row.coverage, 'coverage', errors);
|
|
127
|
+
if (coverage) {
|
|
128
|
+
const telemetry = count(coverage.telemetry, 'coverage.telemetry', errors);
|
|
129
|
+
const total = count(coverage.total, 'coverage.total', errors);
|
|
130
|
+
if (telemetry !== undefined && total !== undefined && telemetry > total)
|
|
131
|
+
errors.push('coverage.telemetry must not exceed coverage.total');
|
|
132
|
+
}
|
|
133
|
+
return errors.length
|
|
134
|
+
? { valid: false, errors }
|
|
135
|
+
: { valid: true, value: value, errors: [] };
|
|
136
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OwnerNotificationPresentation } from '../contracts/owner.js';
|
|
2
|
+
import type { PubgComparisonPresentation, PubgMatchDetailPresentation, PubgMatchListPresentation, PubgMatchReviewPresentation, PubgPeriodReviewPresentation, PubgPresentation, PubgStatsPresentation, PubgStatusPresentation, PubgTeamDamagePresentation } from '../contracts/pubg.js';
|
|
3
|
+
export interface ValidationResult<T> {
|
|
4
|
+
valid: boolean;
|
|
5
|
+
value?: T;
|
|
6
|
+
errors: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function validatePubgStatusPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgStatusPresentation>;
|
|
9
|
+
export declare function validatePubgStatsPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgStatsPresentation>;
|
|
10
|
+
export declare function validatePubgMatchListPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgMatchListPresentation>;
|
|
11
|
+
export declare function validatePubgComparisonPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgComparisonPresentation>;
|
|
12
|
+
export declare function validatePubgMatchDetailPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgMatchDetailPresentation>;
|
|
13
|
+
export declare function validatePubgMatchReviewPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgMatchReviewPresentation>;
|
|
14
|
+
export declare function validatePubgPeriodReviewPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgPeriodReviewPresentation>;
|
|
15
|
+
export declare function validatePubgTeamDamagePresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgTeamDamagePresentation>;
|
|
16
|
+
export declare function validatePubgPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<PubgPresentation>;
|
|
17
|
+
export declare function validateOwnerNotificationPresentation(value: unknown, knownEvidence?: ReadonlySet<string>): ValidationResult<OwnerNotificationPresentation>;
|
|
18
|
+
export declare function assertValid<T>(validation: ValidationResult<T>): T;
|