@plasius/ai-game 0.5.0 → 0.6.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
@@ -1212,6 +1212,293 @@ function assertAiGameIdentityProjectionContractVersion(value) {
1212
1212
  assertContractVersion3(value);
1213
1213
  }
1214
1214
 
1215
+ // src/observed-events.ts
1216
+ var AI_GAME_OBSERVED_EVENT_LOG_FEATURE_FLAG_ID = "isekai.player-system.logs.enabled";
1217
+ var AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION = "1.0";
1218
+ var AI_GAME_OBSERVED_EVENT_KINDS = [
1219
+ "combat",
1220
+ "crafting",
1221
+ "discovery",
1222
+ "mission",
1223
+ "social",
1224
+ "travel",
1225
+ "world"
1226
+ ];
1227
+ var AI_GAME_OBSERVED_EVENT_SOURCES = [
1228
+ "player-action",
1229
+ "system-observation",
1230
+ "world-state"
1231
+ ];
1232
+ var AI_GAME_OBSERVED_EVENT_VISIBILITIES = [
1233
+ "private",
1234
+ "party",
1235
+ "local",
1236
+ "public"
1237
+ ];
1238
+ var AI_GAME_OBSERVED_EVENT_SIGNIFICANCE = [
1239
+ "routine",
1240
+ "notable",
1241
+ "critical"
1242
+ ];
1243
+ var AI_GAME_GOSSIP_EXPORT_AUDIENCES = [
1244
+ "player",
1245
+ "npc",
1246
+ "public"
1247
+ ];
1248
+ var AI_GAME_OBSERVED_EVENT_MAX_SUMMARY_LENGTH = 500;
1249
+ var AI_GAME_OBSERVED_EVENT_MAX_TAGS = 20;
1250
+ var AI_GAME_OBSERVED_EVENT_MAX_TAG_LENGTH = 64;
1251
+ var AI_GAME_OBSERVED_EVENT_MAX_WINDOW_EVENTS = 100;
1252
+ function freezeReadonlyArray5(items) {
1253
+ return Object.freeze([...items]);
1254
+ }
1255
+ function isMember4(value, members) {
1256
+ return members.includes(value);
1257
+ }
1258
+ function assertNonEmptyString5(value, label) {
1259
+ if (value.trim().length === 0) {
1260
+ throw new Error(`${label} must be a non-empty string`);
1261
+ }
1262
+ }
1263
+ function assertSafeText(value, label, maxLength) {
1264
+ assertNonEmptyString5(value, label);
1265
+ if (value.length > maxLength) {
1266
+ throw new Error(`${label} must be ${maxLength} characters or fewer`);
1267
+ }
1268
+ if ([...value].some((character) => {
1269
+ const codePoint = character.codePointAt(0) ?? 0;
1270
+ return codePoint <= 31 || codePoint === 127;
1271
+ })) {
1272
+ throw new Error(`${label} must not contain control characters`);
1273
+ }
1274
+ }
1275
+ function assertIsoTimestamp3(value, label) {
1276
+ assertNonEmptyString5(value, label);
1277
+ if (Number.isNaN(Date.parse(value))) {
1278
+ throw new Error(`${label} must be an ISO-8601 timestamp`);
1279
+ }
1280
+ }
1281
+ function assertContractVersion4(value) {
1282
+ if (value !== AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION) {
1283
+ throw new Error(
1284
+ `contractVersion must be ${AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION}`
1285
+ );
1286
+ }
1287
+ }
1288
+ function assertArrayLimit(value, label, maximum) {
1289
+ if (value.length > maximum) {
1290
+ throw new Error(`${label} must contain ${maximum} items or fewer`);
1291
+ }
1292
+ }
1293
+ function createStringArray2(values, label, maximum, itemMaximum) {
1294
+ assertArrayLimit(values, label, maximum);
1295
+ const result = values.map((value, index) => {
1296
+ assertSafeText(value, `${label}[${index}]`, itemMaximum);
1297
+ return value.trim();
1298
+ });
1299
+ if (new Set(result).size !== result.length) {
1300
+ throw new Error(`${label} must not contain duplicate values`);
1301
+ }
1302
+ return freezeReadonlyArray5(result);
1303
+ }
1304
+ function assertUniqueIds(values, label) {
1305
+ if (new Set(values).size !== values.length) {
1306
+ throw new Error(`${label} must not contain duplicate values`);
1307
+ }
1308
+ }
1309
+ function cloneObservedEvent(event) {
1310
+ return createAiGameObservedEvent(event);
1311
+ }
1312
+ function cloneRecencyWindow(window) {
1313
+ return createAiGameObservedEventRecencyWindow({
1314
+ contractVersion: window.contractVersion,
1315
+ windowId: window.windowId,
1316
+ startsAtIso: window.startsAtIso,
1317
+ endsAtIso: window.endsAtIso,
1318
+ events: window.events
1319
+ });
1320
+ }
1321
+ function cloneHighlightSummary(summary) {
1322
+ return createAiGameObservedEventHighlightSummary({
1323
+ contractVersion: summary.contractVersion,
1324
+ summaryId: summary.summaryId,
1325
+ windowId: summary.windowId,
1326
+ title: summary.title,
1327
+ summary: summary.summary,
1328
+ significance: summary.significance,
1329
+ eventIds: summary.eventIds,
1330
+ reasonCodes: summary.reasonCodes
1331
+ });
1332
+ }
1333
+ function isAiGameObservedEventKind(value) {
1334
+ return isMember4(value, AI_GAME_OBSERVED_EVENT_KINDS);
1335
+ }
1336
+ function isAiGameObservedEventSource(value) {
1337
+ return isMember4(value, AI_GAME_OBSERVED_EVENT_SOURCES);
1338
+ }
1339
+ function isAiGameObservedEventVisibility(value) {
1340
+ return isMember4(value, AI_GAME_OBSERVED_EVENT_VISIBILITIES);
1341
+ }
1342
+ function isAiGameObservedEventSignificance(value) {
1343
+ return isMember4(value, AI_GAME_OBSERVED_EVENT_SIGNIFICANCE);
1344
+ }
1345
+ function isAiGameGossipExportAudience(value) {
1346
+ return isMember4(value, AI_GAME_GOSSIP_EXPORT_AUDIENCES);
1347
+ }
1348
+ function createAiGameObservedEvent(input) {
1349
+ const contractVersion = input.contractVersion ?? AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION;
1350
+ assertContractVersion4(contractVersion);
1351
+ assertSafeText(input.eventId, "eventId", 200);
1352
+ assertIsoTimestamp3(input.occurredAtIso, "occurredAtIso");
1353
+ assertSafeText(input.subjectRef, "subjectRef", 200);
1354
+ assertSafeText(
1355
+ input.summary,
1356
+ "summary",
1357
+ AI_GAME_OBSERVED_EVENT_MAX_SUMMARY_LENGTH
1358
+ );
1359
+ if (!isAiGameObservedEventKind(input.kind)) {
1360
+ throw new Error(`kind must be one of: ${AI_GAME_OBSERVED_EVENT_KINDS.join(", ")}`);
1361
+ }
1362
+ if (!isAiGameObservedEventSource(input.source)) {
1363
+ throw new Error(
1364
+ `source must be one of: ${AI_GAME_OBSERVED_EVENT_SOURCES.join(", ")}`
1365
+ );
1366
+ }
1367
+ if (!isAiGameObservedEventSignificance(input.significance)) {
1368
+ throw new Error(
1369
+ `significance must be one of: ${AI_GAME_OBSERVED_EVENT_SIGNIFICANCE.join(", ")}`
1370
+ );
1371
+ }
1372
+ if (!isAiGameObservedEventVisibility(input.visibility)) {
1373
+ throw new Error(
1374
+ `visibility must be one of: ${AI_GAME_OBSERVED_EVENT_VISIBILITIES.join(", ")}`
1375
+ );
1376
+ }
1377
+ const tags = createStringArray2(
1378
+ input.tags ?? [],
1379
+ "tags",
1380
+ AI_GAME_OBSERVED_EVENT_MAX_TAGS,
1381
+ AI_GAME_OBSERVED_EVENT_MAX_TAG_LENGTH
1382
+ );
1383
+ return Object.freeze({
1384
+ contractVersion,
1385
+ eventId: input.eventId.trim(),
1386
+ occurredAtIso: input.occurredAtIso,
1387
+ kind: input.kind,
1388
+ source: input.source,
1389
+ subjectRef: input.subjectRef.trim(),
1390
+ summary: input.summary.trim(),
1391
+ significance: input.significance,
1392
+ visibility: input.visibility,
1393
+ tags
1394
+ });
1395
+ }
1396
+ function createAiGameObservedEventRecencyWindow(input) {
1397
+ const contractVersion = input.contractVersion ?? AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION;
1398
+ assertContractVersion4(contractVersion);
1399
+ assertSafeText(input.windowId, "windowId", 200);
1400
+ assertIsoTimestamp3(input.startsAtIso, "startsAtIso");
1401
+ assertIsoTimestamp3(input.endsAtIso, "endsAtIso");
1402
+ const startsAt = Date.parse(input.startsAtIso);
1403
+ const endsAt = Date.parse(input.endsAtIso);
1404
+ if (startsAt > endsAt) {
1405
+ throw new Error("startsAtIso must be before or equal to endsAtIso");
1406
+ }
1407
+ assertArrayLimit(
1408
+ input.events,
1409
+ "events",
1410
+ AI_GAME_OBSERVED_EVENT_MAX_WINDOW_EVENTS
1411
+ );
1412
+ const events = input.events.map(cloneObservedEvent);
1413
+ const eventIds = events.map((event) => event.eventId);
1414
+ assertUniqueIds(eventIds, "events");
1415
+ for (const event of events) {
1416
+ const occurredAt = Date.parse(event.occurredAtIso);
1417
+ if (occurredAt < startsAt || occurredAt > endsAt) {
1418
+ throw new Error(`event ${event.eventId} must occur inside the recency window`);
1419
+ }
1420
+ }
1421
+ return Object.freeze({
1422
+ contractVersion,
1423
+ windowId: input.windowId.trim(),
1424
+ startsAtIso: input.startsAtIso,
1425
+ endsAtIso: input.endsAtIso,
1426
+ events: freezeReadonlyArray5(events)
1427
+ });
1428
+ }
1429
+ function createAiGameObservedEventHighlightSummary(input) {
1430
+ const contractVersion = input.contractVersion ?? AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION;
1431
+ assertContractVersion4(contractVersion);
1432
+ assertSafeText(input.summaryId, "summaryId", 200);
1433
+ assertSafeText(input.windowId, "windowId", 200);
1434
+ assertSafeText(input.title, "title", 200);
1435
+ assertSafeText(
1436
+ input.summary,
1437
+ "summary",
1438
+ AI_GAME_OBSERVED_EVENT_MAX_SUMMARY_LENGTH
1439
+ );
1440
+ if (!isAiGameObservedEventSignificance(input.significance)) {
1441
+ throw new Error(
1442
+ `significance must be one of: ${AI_GAME_OBSERVED_EVENT_SIGNIFICANCE.join(", ")}`
1443
+ );
1444
+ }
1445
+ const eventIds = createStringArray2(input.eventIds, "eventIds", 100, 200);
1446
+ if (eventIds.length === 0) {
1447
+ throw new Error("eventIds must contain at least one event id");
1448
+ }
1449
+ const reasonCodes = createStringArray2(
1450
+ input.reasonCodes ?? [],
1451
+ "reasonCodes",
1452
+ 20,
1453
+ 100
1454
+ );
1455
+ return Object.freeze({
1456
+ contractVersion,
1457
+ summaryId: input.summaryId.trim(),
1458
+ windowId: input.windowId.trim(),
1459
+ title: input.title.trim(),
1460
+ summary: input.summary.trim(),
1461
+ significance: input.significance,
1462
+ eventIds,
1463
+ reasonCodes
1464
+ });
1465
+ }
1466
+ function createAiGameGossipExport(input) {
1467
+ const contractVersion = input.contractVersion ?? AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION;
1468
+ assertContractVersion4(contractVersion);
1469
+ assertSafeText(input.exportId, "exportId", 200);
1470
+ assertIsoTimestamp3(input.exportedAtIso, "exportedAtIso");
1471
+ if (!isAiGameGossipExportAudience(input.audience)) {
1472
+ throw new Error(
1473
+ `audience must be one of: ${AI_GAME_GOSSIP_EXPORT_AUDIENCES.join(", ")}`
1474
+ );
1475
+ }
1476
+ const sourceWindow = cloneRecencyWindow(input.sourceWindow);
1477
+ const eventIds = new Set(sourceWindow.events.map((event) => event.eventId));
1478
+ const highlights = input.highlights.map(cloneHighlightSummary);
1479
+ const summaryIds = highlights.map((summary) => summary.summaryId);
1480
+ assertUniqueIds(summaryIds, "highlights");
1481
+ for (const highlight of highlights) {
1482
+ if (highlight.windowId !== sourceWindow.windowId) {
1483
+ throw new Error("highlight windowId must match sourceWindow windowId");
1484
+ }
1485
+ if (highlight.eventIds.some((eventId) => !eventIds.has(eventId))) {
1486
+ throw new Error("highlight eventIds must reference sourceWindow events");
1487
+ }
1488
+ }
1489
+ return Object.freeze({
1490
+ contractVersion,
1491
+ exportId: input.exportId.trim(),
1492
+ exportedAtIso: input.exportedAtIso,
1493
+ audience: input.audience,
1494
+ sourceWindow,
1495
+ highlights: freezeReadonlyArray5(highlights)
1496
+ });
1497
+ }
1498
+ function assertAiGameObservedEventLogContractVersion(value) {
1499
+ assertContractVersion4(value);
1500
+ }
1501
+
1215
1502
  // src/world-events.ts
1216
1503
  function isCanonicalWorldEvent(event) {
1217
1504
  return event.recordType === "canonical";
@@ -1363,7 +1650,7 @@ var QUIET_MEASURE_JUDGMENT_MISSING_EVIDENCE = [
1363
1650
  "private-or-low-witness-evidence",
1364
1651
  "costly-pressure-event"
1365
1652
  ];
1366
- function isMember4(value, members) {
1653
+ function isMember5(value, members) {
1367
1654
  return members.includes(value);
1368
1655
  }
1369
1656
  function assertRecord(value, label) {
@@ -1404,7 +1691,7 @@ function normalizeTimestamp(value, label) {
1404
1691
  }
1405
1692
  function normalizeMember(value, members, label) {
1406
1693
  const normalized = normalizeNonEmptyString(value, label);
1407
- if (!isMember4(normalized, members)) {
1694
+ if (!isMember5(normalized, members)) {
1408
1695
  throw new TypeError(`${label} must be one of: ${members.join(", ")}.`);
1409
1696
  }
1410
1697
  return normalized;
@@ -1537,13 +1824,13 @@ function normalizeDominantReads(value) {
1537
1824
  return Object.freeze(value.map((entry, index) => normalizeDerivedReadSummary(entry, index)));
1538
1825
  }
1539
1826
  function isQuietMeasureAxis(value) {
1540
- return isMember4(value, QUIET_MEASURE_AXES);
1827
+ return isMember5(value, QUIET_MEASURE_AXES);
1541
1828
  }
1542
1829
  function isQuietMeasureMissionProbeMode(value) {
1543
- return isMember4(value, QUIET_MEASURE_MISSION_PROBE_MODES);
1830
+ return isMember5(value, QUIET_MEASURE_MISSION_PROBE_MODES);
1544
1831
  }
1545
1832
  function isQuietMeasureMissionResolutionShape(value) {
1546
- return isMember4(value, QUIET_MEASURE_MISSION_RESOLUTION_SHAPES);
1833
+ return isMember5(value, QUIET_MEASURE_MISSION_RESOLUTION_SHAPES);
1547
1834
  }
1548
1835
  function createQuietMeasureJudgmentEligibility(input = {}) {
1549
1836
  const repeatedMeaningfulEvidence = normalizeOptionalBoolean(
@@ -2046,6 +2333,7 @@ export {
2046
2333
  AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID,
2047
2334
  AI_GAME_FEATURE_FLAGS,
2048
2335
  AI_GAME_FEATURE_FLAG_ID,
2336
+ AI_GAME_GOSSIP_EXPORT_AUDIENCES,
2049
2337
  AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID,
2050
2338
  AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID,
2051
2339
  AI_GAME_IDENTITY_CONTRACT_VERSION,
@@ -2069,6 +2357,16 @@ export {
2069
2357
  AI_GAME_MISSION_REPEATED_SIGNAL_HANDLING,
2070
2358
  AI_GAME_MISSION_REWARD_CAP_SEMANTICS,
2071
2359
  AI_GAME_MISSION_REWARD_KINDS,
2360
+ AI_GAME_OBSERVED_EVENT_KINDS,
2361
+ AI_GAME_OBSERVED_EVENT_LOG_CONTRACT_VERSION,
2362
+ AI_GAME_OBSERVED_EVENT_LOG_FEATURE_FLAG_ID,
2363
+ AI_GAME_OBSERVED_EVENT_MAX_SUMMARY_LENGTH,
2364
+ AI_GAME_OBSERVED_EVENT_MAX_TAGS,
2365
+ AI_GAME_OBSERVED_EVENT_MAX_TAG_LENGTH,
2366
+ AI_GAME_OBSERVED_EVENT_MAX_WINDOW_EVENTS,
2367
+ AI_GAME_OBSERVED_EVENT_SIGNIFICANCE,
2368
+ AI_GAME_OBSERVED_EVENT_SOURCES,
2369
+ AI_GAME_OBSERVED_EVENT_VISIBILITIES,
2072
2370
  AI_GAME_PACKAGE,
2073
2371
  AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
2074
2372
  AI_GAME_PLAYER_SYSTEM_ALERT_PRIORITIES,
@@ -2126,8 +2424,10 @@ export {
2126
2424
  aiGameFeatureFlags,
2127
2425
  assertAiGameIdentityProjectionContractVersion,
2128
2426
  assertAiGameMissionContractVersion,
2427
+ assertAiGameObservedEventLogContractVersion,
2129
2428
  classifyAiGameTask,
2130
2429
  createAiGameAcademicTrainingSnapshot,
2430
+ createAiGameGossipExport,
2131
2431
  createAiGameIdentityProjectionContract,
2132
2432
  createAiGameIdentitySelfProjection,
2133
2433
  createAiGameIdentityTargetProjection,
@@ -2143,6 +2443,9 @@ export {
2143
2443
  createAiGameMissionRewardBound,
2144
2444
  createAiGameMissionRewardEnvelope,
2145
2445
  createAiGameMissionRewardGrant,
2446
+ createAiGameObservedEvent,
2447
+ createAiGameObservedEventHighlightSummary,
2448
+ createAiGameObservedEventRecencyWindow,
2146
2449
  createAiGamePlayerSystemAlert,
2147
2450
  createAiGamePlayerSystemGuidanceCue,
2148
2451
  createAiGamePlayerSystemPreferenceConfidenceState,
@@ -2162,6 +2465,7 @@ export {
2162
2465
  getAiGamePlayerSystemFocusModeContract,
2163
2466
  getAiGamePlayerSystemGuidanceFallbackContract,
2164
2467
  getAiGamePlayerSystemModuleContract,
2468
+ isAiGameGossipExportAudience,
2165
2469
  isAiGameIdentityKnowledgeState,
2166
2470
  isAiGameIdentityProjectionRead,
2167
2471
  isAiGameIdentityTargetCategory,
@@ -2177,6 +2481,10 @@ export {
2177
2481
  isAiGameMissionRepeatedSignalHandling,
2178
2482
  isAiGameMissionRewardCapSemantic,
2179
2483
  isAiGameMissionRewardKind,
2484
+ isAiGameObservedEventKind,
2485
+ isAiGameObservedEventSignificance,
2486
+ isAiGameObservedEventSource,
2487
+ isAiGameObservedEventVisibility,
2180
2488
  isAiGamePlayerSystemAlertDeliverable,
2181
2489
  isAiGamePlayerSystemAlertPriority,
2182
2490
  isAiGamePlayerSystemConfidenceBand,