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