@plasius/ai-game 0.1.2 → 0.1.6

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
@@ -1,17 +1,724 @@
1
+ // src/points-store.ts
2
+ var AI_GAME_POINTS_STORE_FEATURE_FLAG_ID = "isekai.player-system.points-store.enabled";
3
+ var AI_GAME_POINTS_LEDGER_IDS = ["pp", "esp", "tis", "dis"];
4
+ var AI_GAME_PLAYER_EVOLUTION_STAGES = ["proto-social", "social-lock"];
5
+ var AI_GAME_POINTS_AUTHORITY_BANDS = [
6
+ "self",
7
+ "frontier",
8
+ "civic",
9
+ "divine"
10
+ ];
11
+ var AI_GAME_POINTS_AUTHORITY_SYSTEMS = [
12
+ "player-system",
13
+ "exploration-system",
14
+ "territorial-influence-system",
15
+ "divine-influence-system"
16
+ ];
17
+ var AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER = Object.freeze({
18
+ pp: Object.freeze({
19
+ ledgerId: "pp",
20
+ authorityBand: "self",
21
+ authoritySystem: "player-system",
22
+ requiresWorldAuthority: false,
23
+ combatSafeOnly: false
24
+ }),
25
+ esp: Object.freeze({
26
+ ledgerId: "esp",
27
+ authorityBand: "frontier",
28
+ authoritySystem: "exploration-system",
29
+ requiresWorldAuthority: false,
30
+ combatSafeOnly: true
31
+ }),
32
+ tis: Object.freeze({
33
+ ledgerId: "tis",
34
+ authorityBand: "civic",
35
+ authoritySystem: "territorial-influence-system",
36
+ requiresWorldAuthority: true,
37
+ combatSafeOnly: false
38
+ }),
39
+ dis: Object.freeze({
40
+ ledgerId: "dis",
41
+ authorityBand: "divine",
42
+ authoritySystem: "divine-influence-system",
43
+ requiresWorldAuthority: true,
44
+ combatSafeOnly: false
45
+ })
46
+ });
47
+ var AI_GAME_DEFAULT_POINTS_SPEND_POLICIES = Object.freeze([
48
+ Object.freeze({
49
+ policyId: "pp-personal-respec",
50
+ ledgerId: "pp",
51
+ authorityBoundary: AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER.pp,
52
+ actions: Object.freeze([
53
+ Object.freeze({
54
+ actionId: "return-to-slime",
55
+ title: "Return to slime",
56
+ cost: 12,
57
+ prerequisiteCodes: Object.freeze(["proto-social-window-open", "single-use-remaining"]),
58
+ consequenceCodes: Object.freeze(["reset-social-form", "consume-pp-balance"])
59
+ })
60
+ ])
61
+ }),
62
+ Object.freeze({
63
+ policyId: "esp-exploration-routing",
64
+ ledgerId: "esp",
65
+ authorityBoundary: AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER.esp,
66
+ actions: Object.freeze([
67
+ Object.freeze({
68
+ actionId: "fast-travel-upgrade",
69
+ title: "Unlock frontier fast travel",
70
+ cost: 8,
71
+ prerequisiteCodes: Object.freeze(["frontier-route-discovered", "out-of-combat-only"]),
72
+ consequenceCodes: Object.freeze(["reduce-route-friction"])
73
+ })
74
+ ])
75
+ }),
76
+ Object.freeze({
77
+ policyId: "tis-civic-investment",
78
+ ledgerId: "tis",
79
+ authorityBoundary: AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER.tis,
80
+ actions: Object.freeze([
81
+ Object.freeze({
82
+ actionId: "district-favor",
83
+ title: "Commit district influence favor",
84
+ cost: 5,
85
+ prerequisiteCodes: Object.freeze(["civic-authority-approval"]),
86
+ consequenceCodes: Object.freeze(["alter-territorial-standing"])
87
+ })
88
+ ])
89
+ }),
90
+ Object.freeze({
91
+ policyId: "dis-divine-covenant",
92
+ ledgerId: "dis",
93
+ authorityBoundary: AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER.dis,
94
+ actions: Object.freeze([
95
+ Object.freeze({
96
+ actionId: "divine-oath",
97
+ title: "Bind a divine covenant",
98
+ cost: 3,
99
+ prerequisiteCodes: Object.freeze(["divine-clearance-granted"]),
100
+ consequenceCodes: Object.freeze(["alter-divine-standing"])
101
+ })
102
+ ])
103
+ })
104
+ ]);
105
+ var AI_GAME_PROTO_SOCIAL_DEVOLUTION_POLICY = Object.freeze({
106
+ actionId: "return-to-slime",
107
+ ledgerId: "pp",
108
+ cost: 12,
109
+ requiredEvolutionStage: "proto-social",
110
+ closesAtEvolutionStage: "social-lock",
111
+ singleUse: true,
112
+ authorityBoundary: AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER.pp,
113
+ prerequisiteCodes: Object.freeze(["proto-social-window-open", "single-use-remaining"]),
114
+ consequenceCodes: Object.freeze(["reset-social-form", "consume-pp-balance"])
115
+ });
116
+ function normalizeNonNegativeInteger(value) {
117
+ if (!Number.isFinite(value)) {
118
+ return 0;
119
+ }
120
+ return Math.max(0, Math.trunc(value));
121
+ }
122
+ function isAiGamePointsLedgerId(value) {
123
+ return AI_GAME_POINTS_LEDGER_IDS.includes(value);
124
+ }
125
+ function isAiGamePlayerEvolutionStage(value) {
126
+ return AI_GAME_PLAYER_EVOLUTION_STAGES.includes(value);
127
+ }
128
+ function resolveAiGamePointsAuthorityBoundary(ledgerId) {
129
+ return AI_GAME_POINTS_AUTHORITY_BOUNDARY_BY_LEDGER[ledgerId];
130
+ }
131
+ function createAiGamePointsLedgerSnapshot(input) {
132
+ return Object.freeze({
133
+ ledgerId: input.ledgerId,
134
+ balance: normalizeNonNegativeInteger(input.balance),
135
+ earnedTotal: normalizeNonNegativeInteger(input.earnedTotal),
136
+ spentTotal: normalizeNonNegativeInteger(input.spentTotal),
137
+ committedTotal: normalizeNonNegativeInteger(input.committedTotal),
138
+ asOfEpochMs: input.asOfEpochMs
139
+ });
140
+ }
141
+ function getDefaultAiGamePointsSpendPolicies() {
142
+ return AI_GAME_DEFAULT_POINTS_SPEND_POLICIES;
143
+ }
144
+ function getAiGameProtoSocialDevolutionPolicy() {
145
+ return AI_GAME_PROTO_SOCIAL_DEVOLUTION_POLICY;
146
+ }
147
+ function evaluateAiGameProtoSocialDevolutionEligibility(input) {
148
+ const reasonCodes = [];
149
+ const policy = AI_GAME_PROTO_SOCIAL_DEVOLUTION_POLICY;
150
+ const currentBalance = normalizeNonNegativeInteger(input.currentBalance);
151
+ if (input.evolutionStage !== policy.requiredEvolutionStage) {
152
+ reasonCodes.push("devolution-window-closed");
153
+ }
154
+ if (input.alreadyUsed) {
155
+ reasonCodes.push("devolution-already-used");
156
+ }
157
+ if (currentBalance < policy.cost) {
158
+ reasonCodes.push("insufficient-pp-balance");
159
+ }
160
+ if (reasonCodes.length === 0) {
161
+ reasonCodes.push("devolution-allowed");
162
+ }
163
+ return Object.freeze({
164
+ available: reasonCodes.length === 1 && reasonCodes[0] === "devolution-allowed",
165
+ reasonCodes: Object.freeze(reasonCodes),
166
+ policy
167
+ });
168
+ }
169
+
170
+ // src/world-events.ts
171
+ function isCanonicalWorldEvent(event) {
172
+ return event.recordType === "canonical";
173
+ }
174
+ function isCandidateWorldEvent(event) {
175
+ return event.recordType === "candidate";
176
+ }
177
+ var WORLD_IMPACT_SCALE_LIMIT = 100;
178
+ function clampImpactValue(value) {
179
+ if (!Number.isFinite(value)) {
180
+ return 0;
181
+ }
182
+ return Math.max(0, Math.min(WORLD_IMPACT_SCALE_LIMIT, value));
183
+ }
184
+ function normalizeIncidentImpactVector(impact) {
185
+ return Object.freeze({
186
+ security: clampImpactValue(Number(impact.security ?? 0)),
187
+ economy: clampImpactValue(Number(impact.economy ?? 0)),
188
+ ecology: clampImpactValue(Number(impact.ecology ?? 0)),
189
+ politics: clampImpactValue(Number(impact.politics ?? 0)),
190
+ morale: clampImpactValue(Number(impact.morale ?? 0)),
191
+ magic: clampImpactValue(Number(impact.magic ?? 0)),
192
+ population: clampImpactValue(Number(impact.population ?? 0))
193
+ });
194
+ }
195
+ function isIncidentResolved(incident) {
196
+ return incident.lifecycle === "resolved" || incident.lifecycle === "expired";
197
+ }
198
+
199
+ // src/gossip.ts
200
+ function isGossipTopicActive(topic, nowEpochMs = Date.now()) {
201
+ return topic.status === "active" && topic.expiresAtEpochMs > nowEpochMs && topic.payload.certainty >= 0.35;
202
+ }
203
+ function isGossipTopicCorrected(topic) {
204
+ return topic.status === "corrected";
205
+ }
206
+ function matchSegmentAudience(sourceValue, targetValue, fallback) {
207
+ if (sourceValue.length === 0 || targetValue.length === 0) {
208
+ return fallback;
209
+ }
210
+ return sourceValue.some((value) => targetValue.includes(value));
211
+ }
212
+ function projectTopicForAudience(topic, projection, nowEpochMs = Date.now()) {
213
+ if (!isGossipTopicActive(topic, nowEpochMs)) {
214
+ return {
215
+ topicId: topic.topicId,
216
+ visible: false,
217
+ reasons: ["inactive-or-expired-topic"]
218
+ };
219
+ }
220
+ const hasMatchingRule = projection.segmentRules.some(
221
+ (rule) => matchSegmentAudience(rule.locality, [projection.locality], true) && matchSegmentAudience(rule.factions, [projection.faction], false)
222
+ );
223
+ if (!hasMatchingRule) {
224
+ return {
225
+ topicId: topic.topicId,
226
+ visible: false,
227
+ reasons: ["audience-not-authorized"]
228
+ };
229
+ }
230
+ if (projection.projectionMode === "segment-level" && topic.audienceScope === "public") {
231
+ return {
232
+ topicId: topic.topicId,
233
+ visible: true,
234
+ redactedPayload: topic.payload,
235
+ reasons: ["segment-level-allowed"]
236
+ };
237
+ }
238
+ if (projection.projectionMode === "npc-level" && projection.requestedByNpcRef && topic.audienceScope === "public" && projection.requestedByNpcRef.length > 0) {
239
+ return {
240
+ topicId: topic.topicId,
241
+ visible: true,
242
+ redactedPayload: topic.payload,
243
+ reasons: ["npc-level-allowed"]
244
+ };
245
+ }
246
+ if (projection.projectionMode === "npc-level" && projection.requestedByNpcRef && topic.audienceScope !== "public" && projection.requestedByNpcRef.length > 0) {
247
+ return {
248
+ topicId: topic.topicId,
249
+ visible: true,
250
+ redactedPayload: topic.payload,
251
+ reasons: ["npc-level-allowed"]
252
+ };
253
+ }
254
+ return {
255
+ topicId: topic.topicId,
256
+ visible: false,
257
+ reasons: ["scope-constraints"]
258
+ };
259
+ }
260
+
1
261
  // src/index.ts
2
262
  var AI_GAME_PACKAGE = "@plasius/ai-game";
3
- var AI_GAME_FEATURE_FLAG_ID = "ai.game.enabled";
4
263
  var AI_GAME_ENV_PREFIX = "AI_GAME";
264
+ var AI_GAME_FEATURE_FLAG_ID = "ai.game.enabled";
265
+ var AI_GAME_EVENT_CONTRACTS_FEATURE_FLAG_ID = "ai.game.event-recorder.contracts.enabled";
266
+ var AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID = "ai.game.event-recorder.ingestion.enabled";
267
+ var AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID = "ai.game.event-recorder.impact.enabled";
268
+ var AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID = "ai.game.npc-gossip.topics.enabled";
269
+ var AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID = "ai.game.npc-gossip.perspective.enabled";
270
+ var AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID = "ai.game.npc-gossip.lifecycle.enabled";
271
+ var AI_GAME_FEATURE_FLAGS = {
272
+ workloads: AI_GAME_FEATURE_FLAG_ID,
273
+ ttsCacheEnabled: "ai.tts.cache.enabled",
274
+ ttsNearReuseEnabled: "ai.tts.near-reuse.enabled"
275
+ };
276
+ var AI_GAME_TASK_KINDS = [
277
+ "player-action-validation",
278
+ "npc-action",
279
+ "npc-dialogue",
280
+ "gossip",
281
+ "governance-feedback",
282
+ "feedback",
283
+ "unknown"
284
+ ];
285
+ var AI_GAME_TASK_RISK_CLASSES = [
286
+ "low",
287
+ "medium",
288
+ "high",
289
+ "critical"
290
+ ];
291
+ var AI_GAME_TASK_AUTHORITY_BOUNDARIES = [
292
+ "deterministic",
293
+ "human-review",
294
+ "operator-review",
295
+ "blocked"
296
+ ];
297
+ var AI_GAME_TASK_DECISIONS = ["allow", "operator-review", "blocked"];
298
+ var AI_GAME_TASK_RESULTS = ["allow", "defer", "deny"];
299
+ var AI_GAME_TTS_CACHE_POLICIES = [
300
+ "exact-cache",
301
+ "near-cache",
302
+ "no-cache"
303
+ ];
304
+ var AI_GAME_ACTOR_ROLES = ["player", "npc", "operator", "system"];
305
+ var AI_GAME_TASK_PROFILE_BY_KIND = {
306
+ "player-action-validation": {
307
+ riskClass: "medium",
308
+ authorityBoundary: "human-review",
309
+ keywords: ["move", "attack", "collect", "use", "open", "pick", "trade", "target"]
310
+ },
311
+ "npc-action": {
312
+ riskClass: "high",
313
+ authorityBoundary: "operator-review",
314
+ keywords: ["summon", "kill", "ban", "spawn", "eject", "resurrect", "npc action", "npc-action"]
315
+ },
316
+ "npc-dialogue": {
317
+ riskClass: "low",
318
+ authorityBoundary: "deterministic",
319
+ keywords: ["say", "says", "reply", "chat", "dialogue", "greet", "warn", "request"]
320
+ },
321
+ gossip: {
322
+ riskClass: "high",
323
+ authorityBoundary: "operator-review",
324
+ keywords: ["rumor", "rumors", "gossip", "hearsay", "whisper", "spread", "denounce"]
325
+ },
326
+ "governance-feedback": {
327
+ riskClass: "critical",
328
+ authorityBoundary: "blocked",
329
+ keywords: ["punish", "expel", "revoke", "ban", "forbid", "seize"]
330
+ },
331
+ feedback: {
332
+ riskClass: "low",
333
+ authorityBoundary: "operator-review",
334
+ keywords: ["feedback", "rating", "report", "score", "review", "complaint"]
335
+ },
336
+ unknown: {
337
+ riskClass: "low",
338
+ authorityBoundary: "deterministic",
339
+ keywords: [""]
340
+ }
341
+ };
342
+ var AI_GAME_TASK_KEYWORD_PATTERNS = {
343
+ "player-action-validation": buildTaskPattern(
344
+ AI_GAME_TASK_PROFILE_BY_KIND["player-action-validation"].keywords
345
+ ),
346
+ "npc-action": buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND["npc-action"].keywords),
347
+ "npc-dialogue": buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND["npc-dialogue"].keywords),
348
+ gossip: buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND.gossip.keywords),
349
+ "governance-feedback": buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND["governance-feedback"].keywords),
350
+ feedback: buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND.feedback.keywords),
351
+ unknown: buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND.unknown.keywords)
352
+ };
353
+ function nowIsoString() {
354
+ return (/* @__PURE__ */ new Date()).toISOString();
355
+ }
356
+ function escapeRegExp(value) {
357
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
358
+ }
359
+ function normalizeToken(value) {
360
+ return value.trim().replace(/\s+/g, " ");
361
+ }
362
+ function buildTaskPattern(keywords) {
363
+ return new RegExp(
364
+ keywords.filter((keyword) => keyword.length > 0).map((keyword) => `\\b${escapeRegExp(keyword)}\\b`).join("|") || "^$",
365
+ "i"
366
+ );
367
+ }
368
+ function uniqueStrings(values) {
369
+ return Array.from(new Set(values.filter((value) => value.length > 0)));
370
+ }
371
+ function isFeatureEnabled(featureFlag, snapshot = {}) {
372
+ return snapshot[featureFlag] === true;
373
+ }
374
+ function normalizeTaskText(value) {
375
+ return value.trim().replace(/\s+/g, " ").toLowerCase();
376
+ }
377
+ function isActorRole(role) {
378
+ return role ?? "player";
379
+ }
380
+ function normalizeTaskKind(taskKind) {
381
+ if (!taskKind) {
382
+ return void 0;
383
+ }
384
+ return AI_GAME_TASK_KINDS.includes(taskKind) ? taskKind : "unknown";
385
+ }
386
+ function classifyAiGameTask(taskText) {
387
+ const normalized = normalizeTaskText(taskText);
388
+ if (!normalized) {
389
+ return "unknown";
390
+ }
391
+ for (const taskKind of AI_GAME_TASK_KINDS) {
392
+ if (AI_GAME_TASK_KEYWORD_PATTERNS[taskKind].test(normalized)) {
393
+ return taskKind;
394
+ }
395
+ }
396
+ return "unknown";
397
+ }
398
+ function resolveTaskAuthority(taskKind) {
399
+ return AI_GAME_TASK_PROFILE_BY_KIND[taskKind];
400
+ }
401
+ function resolveTaskDecision(taskKind, profile, actorRole) {
402
+ if (profile.authorityBoundary === "blocked") {
403
+ return {
404
+ decision: "blocked",
405
+ needsOperatorReview: actorRole !== "system"
406
+ };
407
+ }
408
+ if (profile.authorityBoundary === "deterministic") {
409
+ return {
410
+ decision: "allow",
411
+ needsOperatorReview: false
412
+ };
413
+ }
414
+ if (actorRole === "system") {
415
+ return {
416
+ decision: "allow",
417
+ needsOperatorReview: false
418
+ };
419
+ }
420
+ return {
421
+ decision: "operator-review",
422
+ needsOperatorReview: true
423
+ };
424
+ }
425
+ function buildRequestIds(requests) {
426
+ return uniqueStrings(requests.map((request) => request.taskId.trim()).filter(Boolean));
427
+ }
428
+ function resolveAiGameTaskBatch(input) {
429
+ const actorRole = isActorRole(input.actorRole);
430
+ const featureEnabled = isFeatureEnabled(
431
+ AI_GAME_FEATURE_FLAGS.workloads,
432
+ input.featureFlags
433
+ );
434
+ const reasonCodes = [...input.reasonCodes ?? []];
435
+ const requests = input.requests.map((request) => ({
436
+ ...request,
437
+ taskKind: normalizeTaskKind(request.taskKind) ?? classifyAiGameTask(request.taskText)
438
+ }));
439
+ if (!featureEnabled) {
440
+ reasonCodes.push("game-feature-disabled");
441
+ const requestIds = buildRequestIds(requests);
442
+ return {
443
+ requestedTasks: requestIds,
444
+ taskDecisions: Object.freeze(
445
+ requestIds.map((taskId) => ({
446
+ taskId,
447
+ taskKind: "unknown",
448
+ riskClass: "critical",
449
+ authorityBoundary: "blocked",
450
+ decision: "blocked",
451
+ needsOperatorReview: false,
452
+ reasonCodes: ["feature-disabled"]
453
+ }))
454
+ ),
455
+ allowedTaskIds: Object.freeze([]),
456
+ reviewTaskIds: Object.freeze([]),
457
+ blockedTaskIds: Object.freeze(requestIds),
458
+ needsOperatorReview: false,
459
+ featureEnabled,
460
+ enabledFeatureFlags: [],
461
+ source: "policy-disabled",
462
+ audit: {
463
+ policyId: input.policyId ?? "game-task-policy-v1",
464
+ policyVersion: input.policyVersion ?? "2026-05-01",
465
+ correlationId: input.correlationId ?? crypto.randomUUID(),
466
+ requestId: input.requestId,
467
+ actorId: input.actorId,
468
+ actorRole,
469
+ evaluatedAtUtc: nowIsoString(),
470
+ result: "deny"
471
+ }
472
+ };
473
+ }
474
+ if (requests.length === 0) {
475
+ reasonCodes.push("game-task-empty-request");
476
+ return {
477
+ requestedTasks: Object.freeze([]),
478
+ taskDecisions: Object.freeze([]),
479
+ allowedTaskIds: Object.freeze([]),
480
+ reviewTaskIds: Object.freeze([]),
481
+ blockedTaskIds: Object.freeze([]),
482
+ needsOperatorReview: false,
483
+ featureEnabled,
484
+ enabledFeatureFlags: [AI_GAME_FEATURE_FLAGS.workloads],
485
+ source: "policy-empty",
486
+ audit: {
487
+ policyId: input.policyId ?? "game-task-policy-v1",
488
+ policyVersion: input.policyVersion ?? "2026-05-01",
489
+ correlationId: input.correlationId ?? crypto.randomUUID(),
490
+ requestId: input.requestId,
491
+ actorId: input.actorId,
492
+ actorRole,
493
+ evaluatedAtUtc: nowIsoString(),
494
+ result: "allow"
495
+ }
496
+ };
497
+ }
498
+ const taskDecisions = [];
499
+ for (const request of requests) {
500
+ const taskKind = request.taskKind;
501
+ const profile = resolveTaskAuthority(taskKind);
502
+ const decision = resolveTaskDecision(taskKind, profile, actorRole);
503
+ taskDecisions.push({
504
+ taskId: request.taskId,
505
+ taskKind,
506
+ riskClass: profile.riskClass,
507
+ authorityBoundary: profile.authorityBoundary,
508
+ ...decision,
509
+ reasonCodes: [`task-${taskKind}-${decision.decision}`]
510
+ });
511
+ }
512
+ const allowedTaskIds = [];
513
+ const reviewTaskIds = [];
514
+ const blockedTaskIds = [];
515
+ for (const decision of taskDecisions) {
516
+ if (decision.decision === "allow") {
517
+ allowedTaskIds.push(decision.taskId);
518
+ } else if (decision.decision === "operator-review") {
519
+ reviewTaskIds.push(decision.taskId);
520
+ } else {
521
+ blockedTaskIds.push(decision.taskId);
522
+ }
523
+ reasonCodes.push(...decision.reasonCodes);
524
+ }
525
+ const hasBlockedTasks = blockedTaskIds.length > 0;
526
+ const needsOperatorReview = taskDecisions.some((decision) => decision.needsOperatorReview);
527
+ return {
528
+ requestedTasks: Object.freeze(buildRequestIds(requests)),
529
+ taskDecisions: Object.freeze(taskDecisions),
530
+ allowedTaskIds: Object.freeze(uniqueStrings(allowedTaskIds)),
531
+ reviewTaskIds: Object.freeze(uniqueStrings(reviewTaskIds)),
532
+ blockedTaskIds: Object.freeze(uniqueStrings(blockedTaskIds)),
533
+ needsOperatorReview,
534
+ featureEnabled,
535
+ enabledFeatureFlags: [AI_GAME_FEATURE_FLAGS.workloads],
536
+ source: "policy",
537
+ audit: {
538
+ policyId: input.policyId ?? "game-task-policy-v1",
539
+ policyVersion: input.policyVersion ?? "2026-05-01",
540
+ correlationId: input.correlationId ?? crypto.randomUUID(),
541
+ requestId: input.requestId,
542
+ actorId: input.actorId,
543
+ actorRole,
544
+ evaluatedAtUtc: nowIsoString(),
545
+ result: hasBlockedTasks ? "deny" : needsOperatorReview ? "defer" : "allow"
546
+ }
547
+ };
548
+ }
549
+ function resolveAiGamePlayerAddressText(input) {
550
+ const actorRole = isActorRole(input.actorRole);
551
+ const cacheEnabled = isFeatureEnabled(
552
+ AI_GAME_FEATURE_FLAGS.ttsCacheEnabled,
553
+ input.featureFlags
554
+ );
555
+ const sourceText = normalizeToken(input.playerAddressText);
556
+ const reasonCodes = [...input.reasonCodes ?? []];
557
+ if (!sourceText) {
558
+ reasonCodes.push("tts-empty-text");
559
+ return {
560
+ sourceText,
561
+ renderText: "",
562
+ ttsCachePolicy: "no-cache",
563
+ reasonCodes,
564
+ enabledFeatureFlags: [],
565
+ source: "policy-empty",
566
+ audit: {
567
+ policyId: input.policyId ?? "game-task-policy-v1",
568
+ policyVersion: input.policyVersion ?? "2026-05-01",
569
+ correlationId: input.correlationId ?? crypto.randomUUID(),
570
+ requestId: input.requestId,
571
+ actorId: input.actorId,
572
+ actorRole,
573
+ evaluatedAtUtc: nowIsoString(),
574
+ cachePolicy: "no-cache"
575
+ }
576
+ };
577
+ }
578
+ const aliasEntries = [
579
+ ...uniqueStrings([normalizeToken(input.playerAlias ?? "")]).filter(Boolean).map((alias) => ({
580
+ alias,
581
+ isAccountAlias: false
582
+ })),
583
+ ...uniqueStrings([normalizeToken(input.accountAlias ?? "")]).filter(Boolean).map((alias) => ({
584
+ alias,
585
+ isAccountAlias: true
586
+ }))
587
+ ];
588
+ let renderText = sourceText;
589
+ let replaced = false;
590
+ for (const alias of aliasEntries) {
591
+ const pattern = new RegExp(`\\b${escapeRegExp(alias.alias)}\\b`, "gi");
592
+ if (pattern.test(renderText)) {
593
+ renderText = renderText.replace(pattern, alias.isAccountAlias ? "[ACCOUNT]" : "[PLAYER]");
594
+ replaced = true;
595
+ reasonCodes.push(`tts-redacted-${alias.alias.toLowerCase()}`);
596
+ }
597
+ }
598
+ const nearCacheEnabled = isFeatureEnabled(
599
+ AI_GAME_FEATURE_FLAGS.ttsNearReuseEnabled,
600
+ input.featureFlags
601
+ );
602
+ if (!cacheEnabled) {
603
+ reasonCodes.push("tts-cache-disabled");
604
+ return {
605
+ sourceText,
606
+ renderText,
607
+ ttsCachePolicy: "no-cache",
608
+ reasonCodes,
609
+ enabledFeatureFlags: [],
610
+ source: "policy-disabled",
611
+ audit: {
612
+ policyId: input.policyId ?? "game-task-policy-v1",
613
+ policyVersion: input.policyVersion ?? "2026-05-01",
614
+ correlationId: input.correlationId ?? crypto.randomUUID(),
615
+ requestId: input.requestId,
616
+ actorId: input.actorId,
617
+ actorRole,
618
+ evaluatedAtUtc: nowIsoString(),
619
+ cachePolicy: "no-cache"
620
+ }
621
+ };
622
+ }
623
+ const cachePolicy = !replaced ? "exact-cache" : nearCacheEnabled ? "near-cache" : "no-cache";
624
+ if (cachePolicy === "exact-cache") {
625
+ reasonCodes.push("tts-cache-exact");
626
+ }
627
+ if (cachePolicy === "near-cache") {
628
+ reasonCodes.push("tts-cache-near");
629
+ }
630
+ if (cachePolicy === "no-cache") {
631
+ reasonCodes.push("tts-cache-not-available");
632
+ }
633
+ return {
634
+ sourceText,
635
+ renderText,
636
+ ttsCachePolicy: cachePolicy,
637
+ reasonCodes,
638
+ enabledFeatureFlags: Object.freeze([
639
+ AI_GAME_FEATURE_FLAGS.workloads,
640
+ AI_GAME_FEATURE_FLAGS.ttsCacheEnabled,
641
+ ...nearCacheEnabled ? [AI_GAME_FEATURE_FLAGS.ttsNearReuseEnabled] : []
642
+ ]),
643
+ source: "policy",
644
+ audit: {
645
+ policyId: input.policyId ?? "game-task-policy-v1",
646
+ policyVersion: input.policyVersion ?? "2026-05-01",
647
+ correlationId: input.correlationId ?? crypto.randomUUID(),
648
+ requestId: input.requestId,
649
+ actorId: input.actorId,
650
+ actorRole,
651
+ evaluatedAtUtc: nowIsoString(),
652
+ cachePolicy
653
+ }
654
+ };
655
+ }
5
656
  var packageDescriptor = Object.freeze({
6
657
  packageName: AI_GAME_PACKAGE,
7
658
  featureFlagId: AI_GAME_FEATURE_FLAG_ID,
8
659
  envPrefix: AI_GAME_ENV_PREFIX,
9
- summary: "Game-domain AI contracts for player action validation, NPC actions, gossip, and feedback."
660
+ summary: "Game-domain AI contracts for event recorder, canonical world-state, and NPC gossip projections."
661
+ });
662
+ var aiGameFeatureFlags = Object.freeze({
663
+ contract: AI_GAME_EVENT_CONTRACTS_FEATURE_FLAG_ID,
664
+ ingestion: AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID,
665
+ incident: AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID,
666
+ gossipTopics: AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID,
667
+ gossipPerspective: AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
668
+ gossipLifecycle: AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID,
669
+ pointsStore: AI_GAME_POINTS_STORE_FEATURE_FLAG_ID
10
670
  });
671
+ var gameEventFeatureFlags = Object.freeze([
672
+ aiGameFeatureFlags.contract,
673
+ aiGameFeatureFlags.ingestion,
674
+ aiGameFeatureFlags.incident,
675
+ aiGameFeatureFlags.gossipTopics,
676
+ aiGameFeatureFlags.gossipPerspective,
677
+ aiGameFeatureFlags.gossipLifecycle,
678
+ aiGameFeatureFlags.pointsStore
679
+ ]);
11
680
  export {
681
+ AI_GAME_ACTOR_ROLES,
12
682
  AI_GAME_ENV_PREFIX,
683
+ AI_GAME_EVENT_CONTRACTS_FEATURE_FLAG_ID,
684
+ AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID,
685
+ AI_GAME_FEATURE_FLAGS,
13
686
  AI_GAME_FEATURE_FLAG_ID,
687
+ AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID,
688
+ AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID,
689
+ AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID,
14
690
  AI_GAME_PACKAGE,
15
- packageDescriptor
691
+ AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
692
+ AI_GAME_PLAYER_EVOLUTION_STAGES,
693
+ AI_GAME_POINTS_AUTHORITY_BANDS,
694
+ AI_GAME_POINTS_AUTHORITY_SYSTEMS,
695
+ AI_GAME_POINTS_LEDGER_IDS,
696
+ AI_GAME_POINTS_STORE_FEATURE_FLAG_ID,
697
+ AI_GAME_TASK_AUTHORITY_BOUNDARIES,
698
+ AI_GAME_TASK_DECISIONS,
699
+ AI_GAME_TASK_KINDS,
700
+ AI_GAME_TASK_RESULTS,
701
+ AI_GAME_TASK_RISK_CLASSES,
702
+ AI_GAME_TTS_CACHE_POLICIES,
703
+ aiGameFeatureFlags,
704
+ classifyAiGameTask,
705
+ createAiGamePointsLedgerSnapshot,
706
+ evaluateAiGameProtoSocialDevolutionEligibility,
707
+ gameEventFeatureFlags,
708
+ getAiGameProtoSocialDevolutionPolicy,
709
+ getDefaultAiGamePointsSpendPolicies,
710
+ isAiGamePlayerEvolutionStage,
711
+ isAiGamePointsLedgerId,
712
+ isCandidateWorldEvent,
713
+ isCanonicalWorldEvent,
714
+ isGossipTopicActive,
715
+ isGossipTopicCorrected,
716
+ isIncidentResolved,
717
+ normalizeIncidentImpactVector,
718
+ packageDescriptor,
719
+ projectTopicForAudience,
720
+ resolveAiGamePlayerAddressText,
721
+ resolveAiGamePointsAuthorityBoundary,
722
+ resolveAiGameTaskBatch
16
723
  };
17
724
  //# sourceMappingURL=index.js.map