@plasius/ai-game 0.1.13 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -167,6 +167,390 @@ function createAiGameMartialTrainingSnapshot(input) {
167
167
  });
168
168
  }
169
169
 
170
+ // src/player-system.ts
171
+ var AI_GAME_PLAYER_SYSTEM_FEATURE_FLAG_ID = "isekai.player-system.core.enabled";
172
+ var AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION = "1.0";
173
+ var AI_GAME_PLAYER_SYSTEM_FOCUS_MODES = [
174
+ "ambient",
175
+ "focused",
176
+ "combat-safe"
177
+ ];
178
+ var AI_GAME_PLAYER_SYSTEM_INPUT_MODALITIES = ["voice", "touch"];
179
+ var AI_GAME_PLAYER_SYSTEM_MODULES = [
180
+ "identity",
181
+ "missions",
182
+ "guild-quests",
183
+ "event-log",
184
+ "mcc",
185
+ "tutorial",
186
+ "points-store"
187
+ ];
188
+ var AI_GAME_PLAYER_SYSTEM_ALERT_PRIORITIES = [
189
+ "critical",
190
+ "high",
191
+ "normal",
192
+ "low"
193
+ ];
194
+ var AI_GAME_PLAYER_SYSTEM_PREFERENCE_KINDS = [
195
+ "combat",
196
+ "exploration",
197
+ "crafting",
198
+ "social",
199
+ "governance"
200
+ ];
201
+ var AI_GAME_PLAYER_SYSTEM_PREFERENCE_SOURCES = [
202
+ "explicit",
203
+ "observed"
204
+ ];
205
+ var AI_GAME_PLAYER_SYSTEM_CONFIDENCE_BANDS = [
206
+ "low",
207
+ "medium",
208
+ "high"
209
+ ];
210
+ var DEFAULT_FOCUS_MODE_CONTRACTS = Object.freeze({
211
+ ambient: Object.freeze({
212
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
213
+ mode: "ambient",
214
+ acceptsInputModalities: Object.freeze([]),
215
+ allowsFullNavigation: false,
216
+ maximumVisibleModules: 1,
217
+ deliverableAlertPriorities: Object.freeze([
218
+ "critical",
219
+ "high",
220
+ "normal",
221
+ "low"
222
+ ])
223
+ }),
224
+ focused: Object.freeze({
225
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
226
+ mode: "focused",
227
+ acceptsInputModalities: Object.freeze([
228
+ "voice",
229
+ "touch"
230
+ ]),
231
+ allowsFullNavigation: true,
232
+ maximumVisibleModules: 3,
233
+ deliverableAlertPriorities: Object.freeze([
234
+ "critical",
235
+ "high",
236
+ "normal",
237
+ "low"
238
+ ])
239
+ }),
240
+ "combat-safe": Object.freeze({
241
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
242
+ mode: "combat-safe",
243
+ acceptsInputModalities: Object.freeze([
244
+ "voice",
245
+ "touch"
246
+ ]),
247
+ allowsFullNavigation: false,
248
+ maximumVisibleModules: 1,
249
+ deliverableAlertPriorities: Object.freeze([
250
+ "critical",
251
+ "high"
252
+ ])
253
+ })
254
+ });
255
+ var DEFAULT_MODULE_CONTRACTS = Object.freeze({
256
+ identity: Object.freeze({
257
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
258
+ module: "identity",
259
+ requiresFocusedMode: false,
260
+ availableInCombatSafeMode: true,
261
+ supportedInputModalities: Object.freeze([
262
+ "voice",
263
+ "touch"
264
+ ])
265
+ }),
266
+ missions: Object.freeze({
267
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
268
+ module: "missions",
269
+ requiresFocusedMode: true,
270
+ availableInCombatSafeMode: false,
271
+ supportedInputModalities: Object.freeze([
272
+ "voice",
273
+ "touch"
274
+ ])
275
+ }),
276
+ "guild-quests": Object.freeze({
277
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
278
+ module: "guild-quests",
279
+ requiresFocusedMode: true,
280
+ availableInCombatSafeMode: false,
281
+ supportedInputModalities: Object.freeze([
282
+ "voice",
283
+ "touch"
284
+ ])
285
+ }),
286
+ "event-log": Object.freeze({
287
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
288
+ module: "event-log",
289
+ requiresFocusedMode: true,
290
+ availableInCombatSafeMode: false,
291
+ supportedInputModalities: Object.freeze([
292
+ "voice",
293
+ "touch"
294
+ ])
295
+ }),
296
+ mcc: Object.freeze({
297
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
298
+ module: "mcc",
299
+ requiresFocusedMode: true,
300
+ availableInCombatSafeMode: false,
301
+ supportedInputModalities: Object.freeze([
302
+ "voice",
303
+ "touch"
304
+ ])
305
+ }),
306
+ tutorial: Object.freeze({
307
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
308
+ module: "tutorial",
309
+ requiresFocusedMode: true,
310
+ availableInCombatSafeMode: false,
311
+ supportedInputModalities: Object.freeze([
312
+ "voice",
313
+ "touch"
314
+ ])
315
+ }),
316
+ "points-store": Object.freeze({
317
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
318
+ module: "points-store",
319
+ requiresFocusedMode: true,
320
+ availableInCombatSafeMode: false,
321
+ supportedInputModalities: Object.freeze([
322
+ "voice",
323
+ "touch"
324
+ ])
325
+ })
326
+ });
327
+ var DEFAULT_SESSION_MODULES = Object.freeze([DEFAULT_MODULE_CONTRACTS.identity]);
328
+ var AI_GAME_PLAYER_SYSTEM_FOCUS_MODE_CONTRACTS = Object.freeze(
329
+ AI_GAME_PLAYER_SYSTEM_FOCUS_MODES.map(
330
+ (mode) => DEFAULT_FOCUS_MODE_CONTRACTS[mode]
331
+ )
332
+ );
333
+ var AI_GAME_PLAYER_SYSTEM_MODULE_CONTRACTS = Object.freeze(
334
+ AI_GAME_PLAYER_SYSTEM_MODULES.map((module) => DEFAULT_MODULE_CONTRACTS[module])
335
+ );
336
+ function freezeReadonlyArray2(items) {
337
+ return Object.freeze([...items]);
338
+ }
339
+ function assertNonEmptyString2(value, label) {
340
+ if (value.trim().length === 0) {
341
+ throw new Error(`${label} must be a non-empty string`);
342
+ }
343
+ }
344
+ function assertContractVersion(value, label = "contractVersion") {
345
+ if (value !== AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION) {
346
+ throw new Error(`${label} must be ${AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION}`);
347
+ }
348
+ }
349
+ function assertIsoTimestamp(value, label) {
350
+ assertNonEmptyString2(value, label);
351
+ if (Number.isNaN(Date.parse(value))) {
352
+ throw new Error(`${label} must be an ISO-8601 timestamp`);
353
+ }
354
+ }
355
+ function assertConfidenceScore(value, label = "confidenceScore") {
356
+ if (!Number.isFinite(value) || value < 0 || value > 1) {
357
+ throw new Error(`${label} must be between 0 and 1`);
358
+ }
359
+ }
360
+ function assertNonNegativeInteger(value, label) {
361
+ if (!Number.isInteger(value) || value < 0) {
362
+ throw new Error(`${label} must be a non-negative integer`);
363
+ }
364
+ }
365
+ function isMember(value, members) {
366
+ return members.includes(value);
367
+ }
368
+ function isAiGamePlayerSystemFocusMode(value) {
369
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_FOCUS_MODES);
370
+ }
371
+ function isAiGamePlayerSystemInputModality(value) {
372
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_INPUT_MODALITIES);
373
+ }
374
+ function isAiGamePlayerSystemModule(value) {
375
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_MODULES);
376
+ }
377
+ function isAiGamePlayerSystemAlertPriority(value) {
378
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_ALERT_PRIORITIES);
379
+ }
380
+ function isAiGamePlayerSystemPreferenceKind(value) {
381
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_PREFERENCE_KINDS);
382
+ }
383
+ function isAiGamePlayerSystemPreferenceSource(value) {
384
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_PREFERENCE_SOURCES);
385
+ }
386
+ function isAiGamePlayerSystemConfidenceBand(value) {
387
+ return isMember(value, AI_GAME_PLAYER_SYSTEM_CONFIDENCE_BANDS);
388
+ }
389
+ function getAiGamePlayerSystemFocusModeContract(mode) {
390
+ return DEFAULT_FOCUS_MODE_CONTRACTS[mode];
391
+ }
392
+ function getAiGamePlayerSystemModuleContract(module) {
393
+ return DEFAULT_MODULE_CONTRACTS[module];
394
+ }
395
+ function isAiGamePlayerSystemAlertDeliverable(alert, mode) {
396
+ return getAiGamePlayerSystemFocusModeContract(mode).deliverableAlertPriorities.includes(
397
+ alert.priority
398
+ );
399
+ }
400
+ function selectAiGamePlayerSystemAlertsForFocusMode(alerts, mode) {
401
+ return freezeReadonlyArray2(
402
+ alerts.filter((alert) => isAiGamePlayerSystemAlertDeliverable(alert, mode))
403
+ );
404
+ }
405
+ function createAiGamePlayerSystemAlert(input) {
406
+ assertNonEmptyString2(input.alertId, "alertId");
407
+ assertNonEmptyString2(input.title, "title");
408
+ assertNonEmptyString2(input.message, "message");
409
+ assertIsoTimestamp(input.createdAtIso, "createdAtIso");
410
+ assertContractVersion(input.contractVersion ?? AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION);
411
+ if (!isAiGamePlayerSystemAlertPriority(input.priority)) {
412
+ throw new Error("priority must be a supported Player System alert priority");
413
+ }
414
+ if (!isAiGamePlayerSystemModule(input.sourceModule)) {
415
+ throw new Error("sourceModule must be a supported Player System module");
416
+ }
417
+ return Object.freeze({
418
+ ...input,
419
+ contractVersion: input.contractVersion ?? AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION
420
+ });
421
+ }
422
+ function resolveAiGamePlayerSystemConfidenceBand(confidenceScore) {
423
+ assertConfidenceScore(confidenceScore);
424
+ if (confidenceScore >= 0.67) {
425
+ return "high";
426
+ }
427
+ if (confidenceScore >= 0.34) {
428
+ return "medium";
429
+ }
430
+ return "low";
431
+ }
432
+ function createAiGamePlayerSystemPreferenceInput(input) {
433
+ assertNonEmptyString2(input.inputId, "inputId");
434
+ assertIsoTimestamp(input.capturedAtIso, "capturedAtIso");
435
+ assertConfidenceScore(input.confidenceScore);
436
+ if (!isAiGamePlayerSystemPreferenceKind(input.kind)) {
437
+ throw new Error("kind must be a supported Player System preference kind");
438
+ }
439
+ if (!isAiGamePlayerSystemPreferenceSource(input.source)) {
440
+ throw new Error("source must be a supported Player System preference source");
441
+ }
442
+ return Object.freeze({
443
+ ...input,
444
+ reasonCodes: freezeReadonlyArray2(input.reasonCodes ?? [])
445
+ });
446
+ }
447
+ function createAiGamePlayerSystemPreferenceConfidenceState(input) {
448
+ assertConfidenceScore(input.confidenceScore);
449
+ assertNonNegativeInteger(input.sampleCount, "sampleCount");
450
+ assertIsoTimestamp(input.lastUpdatedAtIso, "lastUpdatedAtIso");
451
+ const confidenceBand = resolveAiGamePlayerSystemConfidenceBand(
452
+ input.confidenceScore
453
+ );
454
+ if (input.confidenceBand !== void 0 && input.confidenceBand !== confidenceBand) {
455
+ throw new Error("confidenceBand must match confidenceScore");
456
+ }
457
+ return Object.freeze({
458
+ confidenceScore: input.confidenceScore,
459
+ confidenceBand,
460
+ sampleCount: input.sampleCount,
461
+ lastUpdatedAtIso: input.lastUpdatedAtIso
462
+ });
463
+ }
464
+ function createAiGamePlayerSystemPreferenceProfile(input) {
465
+ assertNonEmptyString2(input.profileId, "profileId");
466
+ const inputs = (input.inputs ?? []).map(
467
+ (preferenceInput) => createAiGamePlayerSystemPreferenceInput(preferenceInput)
468
+ );
469
+ const lastUpdatedAtIso = input.confidence?.lastUpdatedAtIso ?? (/* @__PURE__ */ new Date(0)).toISOString();
470
+ const confidenceScore = input.confidence?.confidenceScore ?? (inputs.length === 0 ? 0 : inputs.reduce((total, preferenceInput) => total + preferenceInput.confidenceScore, 0) / inputs.length);
471
+ const confidence = createAiGamePlayerSystemPreferenceConfidenceState({
472
+ confidenceScore,
473
+ sampleCount: input.confidence?.sampleCount ?? inputs.length,
474
+ lastUpdatedAtIso,
475
+ confidenceBand: input.confidence?.confidenceBand
476
+ });
477
+ return Object.freeze({
478
+ profileId: input.profileId,
479
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
480
+ inputs: freezeReadonlyArray2(inputs),
481
+ confidence
482
+ });
483
+ }
484
+ function createAiGamePlayerSystemSession(input) {
485
+ assertNonEmptyString2(input.sessionId, "sessionId");
486
+ if (!isAiGamePlayerSystemFocusMode(input.focusMode)) {
487
+ throw new Error("focusMode must be a supported Player System focus mode");
488
+ }
489
+ if (input.activeModule !== null && input.activeModule !== void 0 && !isAiGamePlayerSystemModule(input.activeModule)) {
490
+ throw new Error("activeModule must be a supported Player System module");
491
+ }
492
+ const modeContract = getAiGamePlayerSystemFocusModeContract(input.focusMode);
493
+ const modules = freezeReadonlyArray2(
494
+ (input.modules ?? DEFAULT_SESSION_MODULES).map(
495
+ (moduleContract) => Object.freeze({
496
+ ...moduleContract,
497
+ supportedInputModalities: freezeReadonlyArray2(
498
+ moduleContract.supportedInputModalities
499
+ )
500
+ })
501
+ )
502
+ );
503
+ const acceptedInputModalities = freezeReadonlyArray2(
504
+ input.acceptedInputModalities ?? modeContract.acceptsInputModalities
505
+ );
506
+ const pendingAlerts = freezeReadonlyArray2(
507
+ (input.pendingAlerts ?? []).map((alert) => createAiGamePlayerSystemAlert(alert))
508
+ );
509
+ if (modules.length > modeContract.maximumVisibleModules) {
510
+ throw new Error("modules exceed the focus mode visibility limit");
511
+ }
512
+ for (const modality of acceptedInputModalities) {
513
+ if (!isAiGamePlayerSystemInputModality(modality)) {
514
+ throw new Error("acceptedInputModalities contains an unsupported modality");
515
+ }
516
+ }
517
+ if (input.focusMode === "focused" && (!acceptedInputModalities.includes("voice") || !acceptedInputModalities.includes("touch"))) {
518
+ throw new Error("focused sessions must accept both voice and touch input");
519
+ }
520
+ for (const moduleContract of modules) {
521
+ assertContractVersion(moduleContract.contractVersion, "module contractVersion");
522
+ if (!isAiGamePlayerSystemModule(moduleContract.module)) {
523
+ throw new Error("modules contains an unsupported Player System module");
524
+ }
525
+ for (const modality of moduleContract.supportedInputModalities) {
526
+ if (!isAiGamePlayerSystemInputModality(modality)) {
527
+ throw new Error("modules contains an unsupported input modality");
528
+ }
529
+ }
530
+ if (input.focusMode === "combat-safe" && !moduleContract.availableInCombatSafeMode) {
531
+ throw new Error("combat-safe sessions cannot expose unsafe modules");
532
+ }
533
+ }
534
+ if (input.activeModule !== null && input.activeModule !== void 0 && !modules.some((moduleContract) => moduleContract.module === input.activeModule)) {
535
+ throw new Error("activeModule must be included in modules");
536
+ }
537
+ return Object.freeze({
538
+ sessionId: input.sessionId,
539
+ contractVersion: AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
540
+ featureFlagId: AI_GAME_PLAYER_SYSTEM_FEATURE_FLAG_ID,
541
+ focusMode: input.focusMode,
542
+ activeModule: input.activeModule ?? null,
543
+ modules,
544
+ acceptedInputModalities,
545
+ pendingAlerts,
546
+ preferenceProfile: createAiGamePlayerSystemPreferenceProfile({
547
+ profileId: input.preferenceProfile.profileId,
548
+ inputs: input.preferenceProfile.inputs,
549
+ confidence: input.preferenceProfile.confidence
550
+ })
551
+ });
552
+ }
553
+
170
554
  // src/world-events.ts
171
555
  function isCanonicalWorldEvent(event) {
172
556
  return event.recordType === "canonical";
@@ -318,7 +702,7 @@ var QUIET_MEASURE_JUDGMENT_MISSING_EVIDENCE = [
318
702
  "private-or-low-witness-evidence",
319
703
  "costly-pressure-event"
320
704
  ];
321
- function isMember(value, members) {
705
+ function isMember2(value, members) {
322
706
  return members.includes(value);
323
707
  }
324
708
  function assertRecord(value, label) {
@@ -359,7 +743,7 @@ function normalizeTimestamp(value, label) {
359
743
  }
360
744
  function normalizeMember(value, members, label) {
361
745
  const normalized = normalizeNonEmptyString(value, label);
362
- if (!isMember(normalized, members)) {
746
+ if (!isMember2(normalized, members)) {
363
747
  throw new TypeError(`${label} must be one of: ${members.join(", ")}.`);
364
748
  }
365
749
  return normalized;
@@ -492,13 +876,13 @@ function normalizeDominantReads(value) {
492
876
  return Object.freeze(value.map((entry, index) => normalizeDerivedReadSummary(entry, index)));
493
877
  }
494
878
  function isQuietMeasureAxis(value) {
495
- return isMember(value, QUIET_MEASURE_AXES);
879
+ return isMember2(value, QUIET_MEASURE_AXES);
496
880
  }
497
881
  function isQuietMeasureMissionProbeMode(value) {
498
- return isMember(value, QUIET_MEASURE_MISSION_PROBE_MODES);
882
+ return isMember2(value, QUIET_MEASURE_MISSION_PROBE_MODES);
499
883
  }
500
884
  function isQuietMeasureMissionResolutionShape(value) {
501
- return isMember(value, QUIET_MEASURE_MISSION_RESOLUTION_SHAPES);
885
+ return isMember2(value, QUIET_MEASURE_MISSION_RESOLUTION_SHAPES);
502
886
  }
503
887
  function createQuietMeasureJudgmentEligibility(input = {}) {
504
888
  const repeatedMeaningfulEvidence = normalizeOptionalBoolean(
@@ -1006,6 +1390,17 @@ export {
1006
1390
  AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID,
1007
1391
  AI_GAME_PACKAGE,
1008
1392
  AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
1393
+ AI_GAME_PLAYER_SYSTEM_ALERT_PRIORITIES,
1394
+ AI_GAME_PLAYER_SYSTEM_CONFIDENCE_BANDS,
1395
+ AI_GAME_PLAYER_SYSTEM_CONTRACT_VERSION,
1396
+ AI_GAME_PLAYER_SYSTEM_FEATURE_FLAG_ID,
1397
+ AI_GAME_PLAYER_SYSTEM_FOCUS_MODES,
1398
+ AI_GAME_PLAYER_SYSTEM_FOCUS_MODE_CONTRACTS,
1399
+ AI_GAME_PLAYER_SYSTEM_INPUT_MODALITIES,
1400
+ AI_GAME_PLAYER_SYSTEM_MODULES,
1401
+ AI_GAME_PLAYER_SYSTEM_MODULE_CONTRACTS,
1402
+ AI_GAME_PLAYER_SYSTEM_PREFERENCE_KINDS,
1403
+ AI_GAME_PLAYER_SYSTEM_PREFERENCE_SOURCES,
1009
1404
  AI_GAME_QUIET_MEASURE_FEATURE_FLAG_ID,
1010
1405
  AI_GAME_TASK_AUTHORITY_BOUNDARIES,
1011
1406
  AI_GAME_TASK_DECISIONS,
@@ -1045,6 +1440,11 @@ export {
1045
1440
  createAiGameAcademicTrainingSnapshot,
1046
1441
  createAiGameInstitutionEligibility,
1047
1442
  createAiGameMartialTrainingSnapshot,
1443
+ createAiGamePlayerSystemAlert,
1444
+ createAiGamePlayerSystemPreferenceConfidenceState,
1445
+ createAiGamePlayerSystemPreferenceInput,
1446
+ createAiGamePlayerSystemPreferenceProfile,
1447
+ createAiGamePlayerSystemSession,
1048
1448
  createAiGameSpecializationRecommendation,
1049
1449
  createTrainingAcademicMissionPrerequisite as createAiGameTrainingAcademicMissionPrerequisite,
1050
1450
  createTrainingAcademyAdmission as createAiGameTrainingAcademyAdmission,
@@ -1055,6 +1455,16 @@ export {
1055
1455
  createQuietMeasureJudgmentEligibility,
1056
1456
  createQuietMeasureJudgmentResponse,
1057
1457
  gameEventFeatureFlags,
1458
+ getAiGamePlayerSystemFocusModeContract,
1459
+ getAiGamePlayerSystemModuleContract,
1460
+ isAiGamePlayerSystemAlertDeliverable,
1461
+ isAiGamePlayerSystemAlertPriority,
1462
+ isAiGamePlayerSystemConfidenceBand,
1463
+ isAiGamePlayerSystemFocusMode,
1464
+ isAiGamePlayerSystemInputModality,
1465
+ isAiGamePlayerSystemModule,
1466
+ isAiGamePlayerSystemPreferenceKind,
1467
+ isAiGamePlayerSystemPreferenceSource,
1058
1468
  isTrainingAcademicProgressStage as isAiGameTrainingAcademicProgressStage,
1059
1469
  isTrainingAcademyAdmissionDecision as isAiGameTrainingAcademyAdmissionDecision,
1060
1470
  isTrainingAntiSpellCounterWindow as isAiGameTrainingAntiSpellCounterWindow,
@@ -1083,6 +1493,8 @@ export {
1083
1493
  packageDescriptor,
1084
1494
  projectTopicForAudience,
1085
1495
  resolveAiGamePlayerAddressText,
1086
- resolveAiGameTaskBatch
1496
+ resolveAiGamePlayerSystemConfidenceBand,
1497
+ resolveAiGameTaskBatch,
1498
+ selectAiGamePlayerSystemAlertsForFocusMode
1087
1499
  };
1088
1500
  //# sourceMappingURL=index.js.map