@rine-kit/pubg-tools 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ChristmasFox / Arthur Xu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ import type { z } from 'zod';
2
+ import type { PubgDomainService, ToolEnvelope } from '@rine-kit/pubg-domain';
3
+ export interface PubgToolRunContext {
4
+ /** Names the conversation so result sets stay private to it. */
5
+ sessionId: string;
6
+ signal?: AbortSignal;
7
+ }
8
+ export interface PubgToolSpec<S extends z.ZodType = z.ZodType> {
9
+ name: string;
10
+ description: string;
11
+ input: S;
12
+ /**
13
+ * The tool is about people: the host must turn "who" (named players, the team, or the asker) into
14
+ * concrete player ids before the call. Tools about a match or a period of the whole team skip this.
15
+ */
16
+ requiresSubject: boolean;
17
+ run(service: PubgDomainService, input: z.output<S>, context: PubgToolRunContext): Promise<ToolEnvelope>;
18
+ }
19
+ export declare const PUBG_TOOLS: readonly PubgToolSpec[];
@@ -0,0 +1,94 @@
1
+ import { compareInput, matchInput, periodReviewInput, queryStatsInput, resolvePlayersInput, reviewFactsInput, searchMatchesInput, teamDamageInput, } from './schemas.js';
2
+ const spec = (s) => s;
3
+ const selectorInput = (value) => value;
4
+ const withSignal = (context) => context.signal ? { signal: context.signal } : {};
5
+ // Descriptions and the calls into the Domain are those of Lab's plugins/pubg, unchanged.
6
+ export const PUBG_TOOLS = [
7
+ spec({
8
+ name: 'pubg_resolve_players',
9
+ description: 'Resolve configured PUBG players and aliases, or look up one exact official player name.',
10
+ input: resolvePlayersInput,
11
+ requiresSubject: true,
12
+ run: (service, input, context) => service.resolvePlayers({ ...input, sessionId: context.sessionId }),
13
+ }),
14
+ spec({
15
+ name: 'pubg_search_matches',
16
+ description: 'Search bounded PUBG matches and return a fresh resultSetId for follow-up facts or review. Not for 今日/昨日/本周战绩 record requests (use pubg_query_stats).',
17
+ input: searchMatchesInput,
18
+ requiresSubject: true,
19
+ run: (service, input, context) => service.searchMatches({ ...input, sessionId: context.sessionId }),
20
+ }),
21
+ spec({
22
+ name: 'pubg_query_stats',
23
+ description: 'Query deterministic PUBG aggregates for a bounded selector and return validated presentation/displayText.',
24
+ input: queryStatsInput,
25
+ requiresSubject: true,
26
+ run: (service, input, context) => service.queryStats({
27
+ ...input,
28
+ sessionId: context.sessionId,
29
+ selector: selectorInput(input.selector),
30
+ metrics: input.metrics,
31
+ ...withSignal(context),
32
+ }),
33
+ }),
34
+ spec({
35
+ name: 'pubg_compare_stats',
36
+ description: 'Compare two bounded PUBG segments and return independent source ranges with validated presentation/displayText.',
37
+ input: compareInput,
38
+ requiresSubject: true,
39
+ run: (service, input, context) => service.compareStats({
40
+ ...input,
41
+ sessionId: context.sessionId,
42
+ segments: input.segments.map((segment) => ({
43
+ ...segment,
44
+ selector: selectorInput(segment.selector),
45
+ })),
46
+ metrics: input.metrics,
47
+ ...withSignal(context),
48
+ }),
49
+ }),
50
+ spec({
51
+ name: 'pubg_get_match',
52
+ description: 'Get one selected PUBG Match API record and return validated presentation/displayText.',
53
+ input: matchInput,
54
+ requiresSubject: false,
55
+ run: (service, input, context) => service.getMatch({
56
+ ...input,
57
+ sessionId: context.sessionId,
58
+ ...withSignal(context),
59
+ }),
60
+ }),
61
+ spec({
62
+ name: 'pubg_get_review_facts',
63
+ description: 'Get deterministic Telemetry facts for one selected match from a fresh search resultSetId; return validated presentation/displayText.',
64
+ input: reviewFactsInput,
65
+ requiresSubject: true,
66
+ run: (service, input, context) => service.getReviewFacts({
67
+ ...input,
68
+ sessionId: context.sessionId,
69
+ ...withSignal(context),
70
+ }),
71
+ }),
72
+ spec({
73
+ name: 'pubg_get_period_review',
74
+ description: 'Build a bounded multi-match review from a fresh search resultSetId; Domain owns order, freshness, and partial coverage.',
75
+ input: periodReviewInput,
76
+ requiresSubject: true,
77
+ run: (service, input, context) => service.getPeriodReview({
78
+ ...input,
79
+ sessionId: context.sessionId,
80
+ ...withSignal(context),
81
+ }),
82
+ }),
83
+ spec({
84
+ name: 'pubg_query_team_damage',
85
+ description: 'Query bounded directional team-damage facts; provide actor/victim together or omit both.',
86
+ input: teamDamageInput,
87
+ requiresSubject: false,
88
+ run: (service, input, context) => service.queryTeamDamage({
89
+ ...input,
90
+ sessionId: context.sessionId,
91
+ ...withSignal(context),
92
+ }),
93
+ }),
94
+ ];
@@ -0,0 +1,7 @@
1
+ import { type ToolEnvelope } from '@rine-kit/pubg-domain';
2
+ /** The question cannot be answered because nobody (or the wrong people) could be identified. */
3
+ export declare function subjectError(code: string, reason: string): ToolEnvelope;
4
+ /** The model's arguments did not match the tool's contract. */
5
+ export declare function invalidInputError(reason: string): ToolEnvelope;
6
+ /** Configuration or upstream failure while running a tool; details of unexpected errors are not exposed. */
7
+ export declare function runtimeError(error: unknown): ToolEnvelope;
@@ -0,0 +1,43 @@
1
+ import { PubgApiError } from '@rine-kit/pubg-domain';
2
+ const PLUGIN_ID = 'pubg';
3
+ function failure(queryResolved, calculation, error, sourceUnavailable) {
4
+ const now = new Date().toISOString();
5
+ return {
6
+ status: 'error',
7
+ data: {},
8
+ coverage: {
9
+ status: 'SOURCE_UNAVAILABLE',
10
+ complete: false,
11
+ coverageStart: null,
12
+ coverageEnd: null,
13
+ checkedAt: now,
14
+ failedMatchIds: [],
15
+ sourceUnavailable,
16
+ freshness: 'unknown',
17
+ },
18
+ asOf: now,
19
+ metricVersion: 'pubg-metrics-v1',
20
+ queryResolved,
21
+ evidenceRefs: { matchIds: [], playerIds: [], fields: [], calculation },
22
+ error,
23
+ };
24
+ }
25
+ /** The question cannot be answered because nobody (or the wrong people) could be identified. */
26
+ export function subjectError(code, reason) {
27
+ return failure({ tool: PLUGIN_ID, identity: 'required' }, 'identity_resolution', { code, retryable: false, reason }, false);
28
+ }
29
+ /** The model's arguments did not match the tool's contract. */
30
+ export function invalidInputError(reason) {
31
+ return failure({ tool: PLUGIN_ID }, 'input_validation', { code: 'invalid_input', retryable: false, reason: reason.slice(0, 512) }, false);
32
+ }
33
+ /** Configuration or upstream failure while running a tool; details of unexpected errors are not exposed. */
34
+ export function runtimeError(error) {
35
+ const details = error instanceof PubgApiError
36
+ ? { code: error.code, retryable: error.retryable, reason: error.message }
37
+ : {
38
+ code: 'plugin_runtime_error',
39
+ retryable: false,
40
+ reason: 'PUBG plugin configuration or execution failed',
41
+ };
42
+ return failure({ tool: PLUGIN_ID }, 'pubg_plugin_runtime', details, true);
43
+ }
@@ -0,0 +1,8 @@
1
+ export { PUBG_TOOLS } from './catalog.js';
2
+ export type { PubgToolRunContext, PubgToolSpec } from './catalog.js';
3
+ export { invalidInputError, runtimeError, subjectError } from './envelopes.js';
4
+ export { runPubgTool } from './run.js';
5
+ export type { RunPubgToolOptions } from './run.js';
6
+ export { resolveSubject, stripSubject } from './subject.js';
7
+ export type { PubgSubjectAccounts, PubgSubjectHost, PubgSubjectInput } from './subject.js';
8
+ export * from './schemas.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { PUBG_TOOLS } from './catalog.js';
2
+ export { invalidInputError, runtimeError, subjectError } from './envelopes.js';
3
+ export { runPubgTool } from './run.js';
4
+ export { resolveSubject, stripSubject } from './subject.js';
5
+ export * from './schemas.js';
package/dist/run.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { PubgDomainService, ToolEnvelope } from '@rine-kit/pubg-domain';
2
+ import type { PubgToolSpec } from './catalog.js';
3
+ import { type PubgSubjectHost } from './subject.js';
4
+ export interface RunPubgToolOptions {
5
+ /** The Domain service of the one tenant / team the host authorised for this request. */
6
+ service: PubgDomainService;
7
+ host: PubgSubjectHost;
8
+ sessionId: string;
9
+ signal?: AbortSignal;
10
+ }
11
+ /**
12
+ * One tool call, the same on every host: check the arguments, settle who the question is about through the
13
+ * host, call the Domain. Every failure becomes an error envelope the model can relay; nothing throws.
14
+ */
15
+ export declare function runPubgTool(tool: PubgToolSpec, rawInput: unknown, options: RunPubgToolOptions): Promise<ToolEnvelope>;
package/dist/run.js ADDED
@@ -0,0 +1,26 @@
1
+ import { invalidInputError, runtimeError } from './envelopes.js';
2
+ import { resolveSubject, stripSubject, } from './subject.js';
3
+ /**
4
+ * One tool call, the same on every host: check the arguments, settle who the question is about through the
5
+ * host, call the Domain. Every failure becomes an error envelope the model can relay; nothing throws.
6
+ */
7
+ export async function runPubgTool(tool, rawInput, options) {
8
+ try {
9
+ const parsed = tool.input.safeParse(rawInput);
10
+ if (!parsed.success)
11
+ return invalidInputError(parsed.error.issues.map((i) => i.message).join('; '));
12
+ const input = parsed.data;
13
+ const prepared = tool.requiresSubject
14
+ ? await resolveSubject(options.service, options.host, input)
15
+ : stripSubject(input);
16
+ if ('status' in prepared && prepared.status === 'error')
17
+ return prepared;
18
+ return await tool.run(options.service, prepared, {
19
+ sessionId: options.sessionId,
20
+ ...(options.signal ? { signal: options.signal } : {}),
21
+ });
22
+ }
23
+ catch (error) {
24
+ return runtimeError(error);
25
+ }
26
+ }
@@ -0,0 +1,335 @@
1
+ import { z } from 'zod';
2
+ export declare const MAX_SUBJECT_ITEMS = 12;
3
+ export declare const MAX_CATEGORIES = 16;
4
+ /** Who the question is about; the host turns it into concrete player ids (see `PubgSubjectResolver`). */
5
+ export declare const subjectShape: {
6
+ sessionId: z.ZodOptional<z.ZodString>;
7
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
9
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
10
+ team: z.ZodOptional<z.ZodBoolean>;
11
+ };
12
+ export declare const selector: z.ZodUnion<readonly [z.ZodObject<{
13
+ type: z.ZodLiteral<"time_range">;
14
+ from: z.ZodString;
15
+ to: z.ZodString;
16
+ timezone: z.ZodOptional<z.ZodString>;
17
+ businessDayStart: z.ZodOptional<z.ZodString>;
18
+ }, z.core.$strict>, z.ZodObject<{
19
+ type: z.ZodLiteral<"relative_period">;
20
+ value: z.ZodString;
21
+ label: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strict>, z.ZodObject<{
23
+ type: z.ZodLiteral<"last_n_matches">;
24
+ count: z.ZodNumber;
25
+ offset: z.ZodOptional<z.ZodNumber>;
26
+ }, z.core.$strict>, z.ZodObject<{
27
+ type: z.ZodLiteral<"result_set">;
28
+ resultSetId: z.ZodString;
29
+ }, z.core.$strict>]>;
30
+ export declare const searchSelector: z.ZodUnion<readonly [z.ZodObject<{
31
+ type: z.ZodLiteral<"time_range">;
32
+ from: z.ZodString;
33
+ to: z.ZodString;
34
+ timezone: z.ZodOptional<z.ZodString>;
35
+ businessDayStart: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strict>, z.ZodObject<{
37
+ type: z.ZodLiteral<"relative_period">;
38
+ value: z.ZodString;
39
+ label: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strict>]>;
41
+ export declare const teamDamageSource: z.ZodEnum<{
42
+ MELEE: "MELEE";
43
+ GUN: "GUN";
44
+ VEHICLE: "VEHICLE";
45
+ EXPLOSIVE: "EXPLOSIVE";
46
+ }>;
47
+ export declare const teamDamageMeleeKind: z.ZodEnum<{
48
+ PUNCH: "PUNCH";
49
+ KICK: "KICK";
50
+ OTHER: "OTHER";
51
+ }>;
52
+ export declare const metrics: z.ZodEnum<{
53
+ kd: "kd";
54
+ rank: "rank";
55
+ damage: "damage";
56
+ kills: "kills";
57
+ assists: "assists";
58
+ matches: "matches";
59
+ avg_damage: "avg_damage";
60
+ deaths: "deaths";
61
+ wins: "wins";
62
+ top10: "top10";
63
+ dbnos: "dbnos";
64
+ revives: "revives";
65
+ headshot_kills: "headshot_kills";
66
+ survival_time: "survival_time";
67
+ longest_kill: "longest_kill";
68
+ performance_score: "performance_score";
69
+ chicken_index: "chicken_index";
70
+ }>;
71
+ export declare const queryStatsInput: z.ZodObject<{
72
+ selector: z.ZodUnion<readonly [z.ZodObject<{
73
+ type: z.ZodLiteral<"time_range">;
74
+ from: z.ZodString;
75
+ to: z.ZodString;
76
+ timezone: z.ZodOptional<z.ZodString>;
77
+ businessDayStart: z.ZodOptional<z.ZodString>;
78
+ }, z.core.$strict>, z.ZodObject<{
79
+ type: z.ZodLiteral<"relative_period">;
80
+ value: z.ZodString;
81
+ label: z.ZodOptional<z.ZodString>;
82
+ }, z.core.$strict>, z.ZodObject<{
83
+ type: z.ZodLiteral<"last_n_matches">;
84
+ count: z.ZodNumber;
85
+ offset: z.ZodOptional<z.ZodNumber>;
86
+ }, z.core.$strict>, z.ZodObject<{
87
+ type: z.ZodLiteral<"result_set">;
88
+ resultSetId: z.ZodString;
89
+ }, z.core.$strict>]>;
90
+ metrics: z.ZodArray<z.ZodEnum<{
91
+ kd: "kd";
92
+ rank: "rank";
93
+ damage: "damage";
94
+ kills: "kills";
95
+ assists: "assists";
96
+ matches: "matches";
97
+ avg_damage: "avg_damage";
98
+ deaths: "deaths";
99
+ wins: "wins";
100
+ top10: "top10";
101
+ dbnos: "dbnos";
102
+ revives: "revives";
103
+ headshot_kills: "headshot_kills";
104
+ survival_time: "survival_time";
105
+ longest_kill: "longest_kill";
106
+ performance_score: "performance_score";
107
+ chicken_index: "chicken_index";
108
+ }>>;
109
+ operation: z.ZodOptional<z.ZodEnum<{
110
+ report: "report";
111
+ detail: "detail";
112
+ rank: "rank";
113
+ strongest: "strongest";
114
+ weakest: "weakest";
115
+ trend: "trend";
116
+ list: "list";
117
+ }>>;
118
+ groupBy: z.ZodOptional<z.ZodEnum<{
119
+ map: "map";
120
+ match: "match";
121
+ day: "day";
122
+ team: "team";
123
+ player: "player";
124
+ mode: "mode";
125
+ }>>;
126
+ orderBy: z.ZodOptional<z.ZodObject<{
127
+ metric: z.ZodEnum<{
128
+ kd: "kd";
129
+ rank: "rank";
130
+ damage: "damage";
131
+ kills: "kills";
132
+ assists: "assists";
133
+ matches: "matches";
134
+ avg_damage: "avg_damage";
135
+ deaths: "deaths";
136
+ wins: "wins";
137
+ top10: "top10";
138
+ dbnos: "dbnos";
139
+ revives: "revives";
140
+ headshot_kills: "headshot_kills";
141
+ survival_time: "survival_time";
142
+ longest_kill: "longest_kill";
143
+ performance_score: "performance_score";
144
+ chicken_index: "chicken_index";
145
+ }>;
146
+ direction: z.ZodEnum<{
147
+ asc: "asc";
148
+ desc: "desc";
149
+ }>;
150
+ }, z.core.$strict>>;
151
+ limit: z.ZodOptional<z.ZodNumber>;
152
+ refresh: z.ZodOptional<z.ZodBoolean>;
153
+ sessionId: z.ZodOptional<z.ZodString>;
154
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
155
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
156
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
157
+ team: z.ZodOptional<z.ZodBoolean>;
158
+ }, z.core.$strict>;
159
+ export declare const compareInput: z.ZodObject<{
160
+ segments: z.ZodArray<z.ZodObject<{
161
+ label: z.ZodString;
162
+ selector: z.ZodUnion<readonly [z.ZodObject<{
163
+ type: z.ZodLiteral<"time_range">;
164
+ from: z.ZodString;
165
+ to: z.ZodString;
166
+ timezone: z.ZodOptional<z.ZodString>;
167
+ businessDayStart: z.ZodOptional<z.ZodString>;
168
+ }, z.core.$strict>, z.ZodObject<{
169
+ type: z.ZodLiteral<"relative_period">;
170
+ value: z.ZodString;
171
+ label: z.ZodOptional<z.ZodString>;
172
+ }, z.core.$strict>, z.ZodObject<{
173
+ type: z.ZodLiteral<"last_n_matches">;
174
+ count: z.ZodNumber;
175
+ offset: z.ZodOptional<z.ZodNumber>;
176
+ }, z.core.$strict>, z.ZodObject<{
177
+ type: z.ZodLiteral<"result_set">;
178
+ resultSetId: z.ZodString;
179
+ }, z.core.$strict>]>;
180
+ }, z.core.$strict>>;
181
+ metrics: z.ZodArray<z.ZodEnum<{
182
+ kd: "kd";
183
+ rank: "rank";
184
+ damage: "damage";
185
+ kills: "kills";
186
+ assists: "assists";
187
+ matches: "matches";
188
+ avg_damage: "avg_damage";
189
+ deaths: "deaths";
190
+ wins: "wins";
191
+ top10: "top10";
192
+ dbnos: "dbnos";
193
+ revives: "revives";
194
+ headshot_kills: "headshot_kills";
195
+ survival_time: "survival_time";
196
+ longest_kill: "longest_kill";
197
+ performance_score: "performance_score";
198
+ chicken_index: "chicken_index";
199
+ }>>;
200
+ groupBy: z.ZodOptional<z.ZodEnum<{
201
+ map: "map";
202
+ day: "day";
203
+ team: "team";
204
+ player: "player";
205
+ mode: "mode";
206
+ }>>;
207
+ orderBy: z.ZodOptional<z.ZodObject<{
208
+ metric: z.ZodEnum<{
209
+ kd: "kd";
210
+ rank: "rank";
211
+ damage: "damage";
212
+ kills: "kills";
213
+ assists: "assists";
214
+ matches: "matches";
215
+ avg_damage: "avg_damage";
216
+ deaths: "deaths";
217
+ wins: "wins";
218
+ top10: "top10";
219
+ dbnos: "dbnos";
220
+ revives: "revives";
221
+ headshot_kills: "headshot_kills";
222
+ survival_time: "survival_time";
223
+ longest_kill: "longest_kill";
224
+ performance_score: "performance_score";
225
+ chicken_index: "chicken_index";
226
+ }>;
227
+ direction: z.ZodEnum<{
228
+ asc: "asc";
229
+ desc: "desc";
230
+ }>;
231
+ }, z.core.$strict>>;
232
+ limit: z.ZodOptional<z.ZodNumber>;
233
+ refresh: z.ZodOptional<z.ZodBoolean>;
234
+ sessionId: z.ZodOptional<z.ZodString>;
235
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
236
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
237
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
238
+ team: z.ZodOptional<z.ZodBoolean>;
239
+ }, z.core.$strict>;
240
+ export declare const resolvePlayersInput: z.ZodObject<{
241
+ refresh: z.ZodOptional<z.ZodBoolean>;
242
+ sessionId: z.ZodOptional<z.ZodString>;
243
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
244
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
245
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
246
+ team: z.ZodOptional<z.ZodBoolean>;
247
+ }, z.core.$strict>;
248
+ export declare const searchMatchesInput: z.ZodObject<{
249
+ selector: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
250
+ type: z.ZodLiteral<"time_range">;
251
+ from: z.ZodString;
252
+ to: z.ZodString;
253
+ timezone: z.ZodOptional<z.ZodString>;
254
+ businessDayStart: z.ZodOptional<z.ZodString>;
255
+ }, z.core.$strict>, z.ZodObject<{
256
+ type: z.ZodLiteral<"relative_period">;
257
+ value: z.ZodString;
258
+ label: z.ZodOptional<z.ZodString>;
259
+ }, z.core.$strict>]>>;
260
+ from: z.ZodOptional<z.ZodString>;
261
+ to: z.ZodOptional<z.ZodString>;
262
+ timezone: z.ZodOptional<z.ZodString>;
263
+ gameMode: z.ZodOptional<z.ZodString>;
264
+ mapName: z.ZodOptional<z.ZodString>;
265
+ sort: z.ZodOptional<z.ZodEnum<{
266
+ asc: "asc";
267
+ desc: "desc";
268
+ }>>;
269
+ page: z.ZodOptional<z.ZodNumber>;
270
+ pageSize: z.ZodOptional<z.ZodNumber>;
271
+ recentN: z.ZodOptional<z.ZodNumber>;
272
+ refresh: z.ZodOptional<z.ZodBoolean>;
273
+ sessionId: z.ZodOptional<z.ZodString>;
274
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
275
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
276
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
277
+ team: z.ZodOptional<z.ZodBoolean>;
278
+ }, z.core.$strict>;
279
+ export declare const matchInput: z.ZodObject<{
280
+ matchId: z.ZodString;
281
+ refresh: z.ZodOptional<z.ZodBoolean>;
282
+ sessionId: z.ZodOptional<z.ZodString>;
283
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
284
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
285
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
286
+ team: z.ZodOptional<z.ZodBoolean>;
287
+ }, z.core.$strict>;
288
+ export declare const reviewFactsInput: z.ZodObject<{
289
+ matchId: z.ZodString;
290
+ searchResultSetId: z.ZodString;
291
+ categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
292
+ refresh: z.ZodOptional<z.ZodBoolean>;
293
+ sessionId: z.ZodOptional<z.ZodString>;
294
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
295
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
296
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
297
+ team: z.ZodOptional<z.ZodBoolean>;
298
+ }, z.core.$strict>;
299
+ export declare const periodReviewInput: z.ZodObject<{
300
+ searchResultSetId: z.ZodString;
301
+ categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
302
+ sessionId: z.ZodOptional<z.ZodString>;
303
+ playerIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
304
+ playerNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
305
+ personIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
306
+ team: z.ZodOptional<z.ZodBoolean>;
307
+ }, z.core.$strict>;
308
+ export declare const teamDamageInput: z.ZodObject<{
309
+ sessionId: z.ZodOptional<z.ZodString>;
310
+ selector: z.ZodUnion<readonly [z.ZodObject<{
311
+ type: z.ZodLiteral<"time_range">;
312
+ from: z.ZodString;
313
+ to: z.ZodString;
314
+ timezone: z.ZodOptional<z.ZodString>;
315
+ businessDayStart: z.ZodOptional<z.ZodString>;
316
+ }, z.core.$strict>, z.ZodObject<{
317
+ type: z.ZodLiteral<"relative_period">;
318
+ value: z.ZodString;
319
+ label: z.ZodOptional<z.ZodString>;
320
+ }, z.core.$strict>]>;
321
+ actorPlayer: z.ZodOptional<z.ZodString>;
322
+ victimPlayer: z.ZodOptional<z.ZodString>;
323
+ source: z.ZodOptional<z.ZodEnum<{
324
+ MELEE: "MELEE";
325
+ GUN: "GUN";
326
+ VEHICLE: "VEHICLE";
327
+ EXPLOSIVE: "EXPLOSIVE";
328
+ }>>;
329
+ meleeKind: z.ZodOptional<z.ZodEnum<{
330
+ PUNCH: "PUNCH";
331
+ KICK: "KICK";
332
+ OTHER: "OTHER";
333
+ }>>;
334
+ refresh: z.ZodOptional<z.ZodBoolean>;
335
+ }, z.core.$strict>;
@@ -0,0 +1,200 @@
1
+ import { z } from 'zod';
2
+ // The input schemas of the PUBG tools, translated one to one from the TypeBox schemas of Lab's
3
+ // plugins/pubg (same fields, bounds and descriptions) so the model sees the same contract on every host.
4
+ export const MAX_SUBJECT_ITEMS = 12;
5
+ export const MAX_CATEGORIES = 16;
6
+ const HHMM = /^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/u;
7
+ const sessionId = z.string().max(256).optional();
8
+ const playerIds = z.array(z.string().min(1).max(128)).max(MAX_SUBJECT_ITEMS).optional();
9
+ const playerNames = z
10
+ .array(z
11
+ .string()
12
+ .min(1)
13
+ .max(128)
14
+ .describe('An explicit PUBG in-game name or configured alias only; never a channel sender/profile name, phone number, or JID.'))
15
+ .max(MAX_SUBJECT_ITEMS)
16
+ .optional();
17
+ const personIds = z
18
+ .array(z
19
+ .string()
20
+ .min(1)
21
+ .max(128)
22
+ .describe('Canonical Person IDs resolved by the host. For a human nickname in a PUBG request, resolve the person first and pass the resolved personId here; never use a channel display name, phone number, or JID.'))
23
+ .max(MAX_SUBJECT_ITEMS)
24
+ .optional();
25
+ const team = z
26
+ .boolean()
27
+ .describe('Explicitly request the configured PUBG team. This is never an implicit fallback for an unbound sender.')
28
+ .optional();
29
+ /** Who the question is about; the host turns it into concrete player ids (see `PubgSubjectResolver`). */
30
+ export const subjectShape = { sessionId, playerIds, playerNames, personIds, team };
31
+ const timeRange = z
32
+ .object({
33
+ type: z.literal('time_range'),
34
+ from: z.string().min(1).max(128),
35
+ to: z.string().min(1).max(128),
36
+ timezone: z.string().max(128).optional(),
37
+ businessDayStart: z.string().regex(HHMM).optional(),
38
+ })
39
+ .strict();
40
+ const relativePeriod = z
41
+ .object({
42
+ type: z.literal('relative_period'),
43
+ value: z
44
+ .string()
45
+ .min(1)
46
+ .max(128)
47
+ .describe('Semantic period such as today, yesterday, day_before_yesterday, or a user-specified relative period; do not calculate timestamps here.'),
48
+ label: z.string().max(128).optional(),
49
+ })
50
+ .strict();
51
+ const lastMatches = z
52
+ .object({
53
+ type: z.literal('last_n_matches'),
54
+ count: z.number().int().min(1).max(100),
55
+ offset: z.number().int().min(0).max(1000).optional(),
56
+ })
57
+ .strict();
58
+ const resultSet = z
59
+ .object({ type: z.literal('result_set'), resultSetId: z.string().min(1).max(256) })
60
+ .strict();
61
+ export const selector = z.union([timeRange, relativePeriod, lastMatches, resultSet]);
62
+ export const searchSelector = z.union([timeRange, relativePeriod]);
63
+ export const teamDamageSource = z.enum(['MELEE', 'GUN', 'EXPLOSIVE', 'VEHICLE']);
64
+ export const teamDamageMeleeKind = z.enum(['KICK', 'PUNCH', 'OTHER']);
65
+ export const metrics = z.enum([
66
+ 'matches',
67
+ 'kills',
68
+ 'assists',
69
+ 'damage',
70
+ 'avg_damage',
71
+ 'kd',
72
+ 'deaths',
73
+ 'wins',
74
+ 'top10',
75
+ 'rank',
76
+ 'dbnos',
77
+ 'revives',
78
+ 'headshot_kills',
79
+ 'survival_time',
80
+ 'longest_kill',
81
+ 'performance_score',
82
+ 'chicken_index',
83
+ ]);
84
+ const groupBy = z.enum(['player', 'match', 'day', 'map', 'mode', 'team']);
85
+ const orderBy = z.object({ metric: metrics, direction: z.enum(['asc', 'desc']) }).strict();
86
+ const limit = z.number().int().min(1).max(100).optional();
87
+ export const queryStatsInput = z
88
+ .object({
89
+ ...subjectShape,
90
+ selector,
91
+ metrics: z.array(metrics).min(1).max(16),
92
+ operation: z
93
+ .enum(['report', 'detail', 'rank', 'strongest', 'weakest', 'trend', 'list'])
94
+ .optional(),
95
+ groupBy: groupBy.optional(),
96
+ orderBy: orderBy.optional(),
97
+ limit,
98
+ refresh: z
99
+ .boolean()
100
+ .describe('Default is true: refresh the upstream match list, then read cached Match/Telemetry facts. Set false only for an explicit cache-only request; never answer from conversation context.')
101
+ .optional(),
102
+ })
103
+ .strict();
104
+ export const compareInput = z
105
+ .object({
106
+ ...subjectShape,
107
+ segments: z
108
+ .array(z.object({ label: z.string().min(1).max(128), selector }).strict())
109
+ .min(2)
110
+ .max(2),
111
+ metrics: z.array(metrics).min(1).max(16),
112
+ groupBy: z.enum(['player', 'day', 'map', 'mode', 'team']).optional(),
113
+ orderBy: orderBy.optional(),
114
+ limit,
115
+ refresh: z
116
+ .boolean()
117
+ .describe('Default is true: refresh both compared segments before reading persistent cached facts; never use prior conversation text as data.')
118
+ .optional(),
119
+ })
120
+ .strict();
121
+ export const resolvePlayersInput = z
122
+ .object({ ...subjectShape, refresh: z.boolean().optional() })
123
+ .strict();
124
+ export const searchMatchesInput = z
125
+ .object({
126
+ ...subjectShape,
127
+ selector: searchSelector.optional(),
128
+ from: z.string().max(128).optional(),
129
+ to: z.string().max(128).optional(),
130
+ timezone: z.string().max(128).optional(),
131
+ gameMode: z.string().max(64).optional(),
132
+ mapName: z.string().max(128).optional(),
133
+ sort: z
134
+ .enum(['asc', 'desc'])
135
+ .describe('Period reviews should use asc for chronological play order; recentN/latest-match lookups use desc.')
136
+ .optional(),
137
+ page: z.number().int().min(0).max(100).optional(),
138
+ pageSize: z.number().int().min(1).max(50).optional(),
139
+ recentN: z
140
+ .number()
141
+ .int()
142
+ .min(1)
143
+ .max(100)
144
+ .describe('Use only for latest/recent-match lookups; omit for a full period review so the Domain defaults to chronological order.')
145
+ .optional(),
146
+ refresh: z.boolean().optional(),
147
+ })
148
+ .strict();
149
+ export const matchInput = z
150
+ .object({ ...subjectShape, matchId: z.string().min(1).max(256), refresh: z.boolean().optional() })
151
+ .strict();
152
+ const categories = z.array(z.string().min(1).max(64)).max(MAX_CATEGORIES).optional();
153
+ export const reviewFactsInput = z
154
+ .object({
155
+ ...subjectShape,
156
+ matchId: z.string().min(1).max(256),
157
+ searchResultSetId: z
158
+ .string()
159
+ .min(1)
160
+ .max(256)
161
+ .describe('resultSetId returned by a fresh pubg_search_matches call in the current turn; stale or omitted search context is rejected.'),
162
+ categories,
163
+ refresh: z.boolean().optional(),
164
+ })
165
+ .strict();
166
+ export const periodReviewInput = z
167
+ .object({
168
+ ...subjectShape,
169
+ searchResultSetId: z
170
+ .string()
171
+ .min(1)
172
+ .max(256)
173
+ .describe('resultSetId returned by a fresh pubg_search_matches call in the current turn; stale or unrelated search context is rejected.'),
174
+ categories,
175
+ })
176
+ .strict();
177
+ export const teamDamageInput = z
178
+ .object({
179
+ sessionId,
180
+ selector: searchSelector,
181
+ actorPlayer: z
182
+ .string()
183
+ .min(1)
184
+ .max(128)
185
+ .describe('Configured PUBG player name, alias, or account ID. Provide together with victimPlayer for one direction; omit both for all directions.')
186
+ .optional(),
187
+ victimPlayer: z
188
+ .string()
189
+ .min(1)
190
+ .max(128)
191
+ .describe('Configured PUBG player name, alias, or account ID. Provide together with actorPlayer for one direction; omit both for all directions.')
192
+ .optional(),
193
+ source: teamDamageSource.optional(),
194
+ meleeKind: teamDamageMeleeKind.optional(),
195
+ refresh: z
196
+ .boolean()
197
+ .describe('Default is true: refresh match discovery and ensure Telemetry for every match in the resolved period.')
198
+ .optional(),
199
+ })
200
+ .strict();
@@ -0,0 +1,30 @@
1
+ import type { PubgDomainService, ToolEnvelope } from '@rine-kit/pubg-domain';
2
+ /** The accounts a question is about, as concrete ids the Domain understands. */
3
+ export interface PubgSubjectAccounts {
4
+ playerIds: string[];
5
+ playerNames?: string[];
6
+ }
7
+ /** What the model may say about who a question concerns (see schemas.subjectShape). */
8
+ export interface PubgSubjectInput {
9
+ playerIds?: string[];
10
+ playerNames?: string[];
11
+ personIds?: string[];
12
+ team?: boolean;
13
+ }
14
+ /** The part of "who is asking" that only the host can know. Never derived from the model's words. */
15
+ export interface PubgSubjectHost {
16
+ /** The asker's own accounts when the model named nobody; an error envelope when they have none. */
17
+ self(): Promise<PubgSubjectAccounts | ToolEnvelope>;
18
+ /** Accounts of persons the host knows by id (its identity store); omit when the host has none. */
19
+ persons?(personIds: string[]): Promise<PubgSubjectAccounts | ToolEnvelope>;
20
+ }
21
+ declare function without<T extends PubgSubjectInput>(input: T): Omit<T, 'personIds' | 'team'>;
22
+ /** Drops the identity fields of a tool that is not about people. */
23
+ export declare const stripSubject: typeof without;
24
+ /**
25
+ * Lab's subject policy, unchanged: `team` is an explicit request for the configured team and cannot be mixed with
26
+ * anything else; explicit players are used as given; otherwise the host decides (persons it knows, or the
27
+ * asker). Nothing falls back to the team implicitly.
28
+ */
29
+ export declare function resolveSubject<T extends PubgSubjectInput>(service: PubgDomainService, host: PubgSubjectHost, input: T): Promise<Omit<T, 'personIds' | 'team'> | ToolEnvelope>;
30
+ export {};
@@ -0,0 +1,37 @@
1
+ import { subjectError } from './envelopes.js';
2
+ const isAccounts = (value) => 'playerIds' in value;
3
+ function without(input) {
4
+ const rest = { ...input };
5
+ delete rest.personIds;
6
+ delete rest.team;
7
+ return rest;
8
+ }
9
+ /** Drops the identity fields of a tool that is not about people. */
10
+ export const stripSubject = without;
11
+ /**
12
+ * Lab's subject policy, unchanged: `team` is an explicit request for the configured team and cannot be mixed with
13
+ * anything else; explicit players are used as given; otherwise the host decides (persons it knows, or the
14
+ * asker). Nothing falls back to the team implicitly.
15
+ */
16
+ export async function resolveSubject(service, host, input) {
17
+ const explicitPlayers = (input.playerIds?.length ?? 0) + (input.playerNames?.length ?? 0);
18
+ const explicitPersons = input.personIds?.length ?? 0;
19
+ if (input.team === true) {
20
+ if (explicitPlayers || explicitPersons)
21
+ return subjectError('identity_subject_conflict', 'team cannot be combined with another subject');
22
+ return { ...without(input), playerIds: service.team.players.map((player) => player.id) };
23
+ }
24
+ if (explicitPlayers) {
25
+ if (explicitPersons)
26
+ return subjectError('identity_subject_conflict', 'personIds cannot be combined with playerIds or playerNames');
27
+ return without(input);
28
+ }
29
+ const accounts = explicitPersons && host.persons ? await host.persons(input.personIds) : await host.self();
30
+ if (!isAccounts(accounts))
31
+ return accounts;
32
+ return {
33
+ ...without(input),
34
+ playerIds: accounts.playerIds,
35
+ ...(accounts.playerNames?.length ? { playerNames: accounts.playerNames } : {}),
36
+ };
37
+ }
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@rine-kit/pubg-tools",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "The PUBG tool catalogue shared by every host: names, descriptions, validated inputs (zod) and the call into PubgDomainService. Hosts add only identity resolution and result delivery. Extracted from Lab's plugins/pubg.",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "zod": "^4.6.7",
22
+ "@rine-kit/pubg-domain": "0.1.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^26.6.5",
26
+ "tsx": "^4.23.15",
27
+ "typescript": "^5.9.2"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+ssh://git@github.com/ChristmasFox/rine-kit.git",
32
+ "directory": "packages/pubg-tools"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.build.json",
36
+ "typecheck": "tsc -p tsconfig.json --noEmit",
37
+ "test": "tsx --test \"tests/**/*.test.ts\""
38
+ }
6
39
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.