@plasius/ai-game 0.1.2 → 0.1.3
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/CHANGELOG.md +20 -1
- package/README.md +22 -5
- package/dist/index.cjs +556 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +392 -2
- package/dist/index.d.ts +392 -2
- package/dist/index.js +527 -3
- package/dist/index.js.map +1 -1
- package/docs/adrs/adr-0002-canonical-world-event-envelope-and-classification.md +27 -0
- package/docs/adrs/adr-0002-game-task-contracts.md +29 -0
- package/docs/adrs/adr-0003-authoritative-ingestion-append-only-ledger-and-projections.md +28 -0
- package/docs/adrs/adr-0004-incident-lifecycle-resolution-and-world-impact.md +27 -0
- package/docs/adrs/adr-0005-structured-gossip-topics-as-the-output-boundary.md +26 -0
- package/docs/adrs/adr-0006-perspective-gated-relative-knowledge-projection.md +27 -0
- package/docs/adrs/adr-0007-gossip-spread-decay-correction-and-resolution.md +27 -0
- package/docs/adrs/adr-0008-quiet-measure-public-contracts-and-hidden-runtime-boundary.md +36 -0
- package/docs/adrs/index.md +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
5
|
+
The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/)**, and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0.0.html)**.
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
@@ -18,6 +18,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
18
18
|
- **Security**
|
|
19
19
|
- (placeholder)
|
|
20
20
|
|
|
21
|
+
## [0.1.3] - 2026-06-01
|
|
22
|
+
|
|
23
|
+
- **Added**
|
|
24
|
+
- Implemented canonical world event contracts with candidate and canonical envelopes, taxonomy, payload typing, and visibility classes.
|
|
25
|
+
- Added authoritative ingestion interfaces and replay-safe projection/checkpoint contracts.
|
|
26
|
+
- Added incident lifecycle, resolution link, and impact vector models.
|
|
27
|
+
- Added structured gossip topic contracts with lifecycle, confidence, and perspective projection projections.
|
|
28
|
+
- Documented the public `@plasius/ai-game` contract boundary for Quiet Measure hidden-character inference, mission probes, and Judgment verdict models while keeping raw runtime scores host-private by default.
|
|
29
|
+
|
|
30
|
+
- **Changed**
|
|
31
|
+
- Extended public package surface to include all world-event and gossip contract families needed by `ai-game` ingestion and projection consumers.
|
|
32
|
+
|
|
33
|
+
- **Fixed**
|
|
34
|
+
- (placeholder)
|
|
35
|
+
|
|
36
|
+
- **Security**
|
|
37
|
+
- (placeholder)
|
|
38
|
+
|
|
21
39
|
## [0.1.2] - 2026-05-13
|
|
22
40
|
|
|
23
41
|
- **Added**
|
|
@@ -40,3 +58,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
40
58
|
|
|
41
59
|
[0.1.1]: https://github.com/Plasius-LTD/ai-game/releases/tag/v0.1.1
|
|
42
60
|
[0.1.2]: https://github.com/Plasius-LTD/ai-game/releases/tag/v0.1.2
|
|
61
|
+
[0.1.3]: https://github.com/Plasius-LTD/ai-game/releases/tag/v0.1.3
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Game-domain AI contracts for player action validation, NPC actions, gossip, and
|
|
|
4
4
|
|
|
5
5
|
## Scope
|
|
6
6
|
|
|
7
|
-
This package is part of the layered `@plasius/ai-*` package family. It
|
|
7
|
+
This package is part of the layered `@plasius/ai-*` package family. It exports canonical public contracts for world events, world-event ingestion, incident impact state, and gossip topic projection.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -12,12 +12,20 @@ This package is part of the layered `@plasius/ai-*` package family. It is intent
|
|
|
12
12
|
npm install @plasius/ai-game
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Exports
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import {
|
|
19
|
+
AI_GAME_PACKAGE,
|
|
20
|
+
AI_GAME_FEATURE_FLAG_ID,
|
|
21
|
+
aiGameFeatureFlags,
|
|
22
|
+
packageDescriptor,
|
|
23
|
+
type GameWorldEvent,
|
|
24
|
+
type WorldEventIngestionPort,
|
|
25
|
+
type WorldIncidentThread,
|
|
26
|
+
type GossipTopic,
|
|
27
|
+
type GossipPerspectiveProjection
|
|
28
|
+
} from "@plasius/ai-game";
|
|
21
29
|
```
|
|
22
30
|
|
|
23
31
|
## Development
|
|
@@ -30,6 +38,15 @@ npm run test:coverage
|
|
|
30
38
|
npm run pack:check
|
|
31
39
|
```
|
|
32
40
|
|
|
41
|
+
## Feature flags
|
|
42
|
+
|
|
43
|
+
- `ai.game.event-recorder.contracts.enabled`
|
|
44
|
+
- `ai.game.event-recorder.ingestion.enabled`
|
|
45
|
+
- `ai.game.event-recorder.impact.enabled`
|
|
46
|
+
- `ai.game.npc-gossip.topics.enabled`
|
|
47
|
+
- `ai.game.npc-gossip.perspective.enabled`
|
|
48
|
+
- `ai.game.npc-gossip.lifecycle.enabled`
|
|
49
|
+
|
|
33
50
|
## Governance
|
|
34
51
|
|
|
35
52
|
- Security policy: [SECURITY.md](./SECURITY.md)
|
package/dist/index.cjs
CHANGED
|
@@ -20,26 +20,578 @@ 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
|
-
|
|
33
|
+
AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID: () => AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
|
|
34
|
+
AI_GAME_TASK_AUTHORITY_BOUNDARIES: () => AI_GAME_TASK_AUTHORITY_BOUNDARIES,
|
|
35
|
+
AI_GAME_TASK_DECISIONS: () => AI_GAME_TASK_DECISIONS,
|
|
36
|
+
AI_GAME_TASK_KINDS: () => AI_GAME_TASK_KINDS,
|
|
37
|
+
AI_GAME_TASK_RESULTS: () => AI_GAME_TASK_RESULTS,
|
|
38
|
+
AI_GAME_TASK_RISK_CLASSES: () => AI_GAME_TASK_RISK_CLASSES,
|
|
39
|
+
AI_GAME_TTS_CACHE_POLICIES: () => AI_GAME_TTS_CACHE_POLICIES,
|
|
40
|
+
aiGameFeatureFlags: () => aiGameFeatureFlags,
|
|
41
|
+
classifyAiGameTask: () => classifyAiGameTask,
|
|
42
|
+
gameEventFeatureFlags: () => gameEventFeatureFlags,
|
|
43
|
+
isCandidateWorldEvent: () => isCandidateWorldEvent,
|
|
44
|
+
isCanonicalWorldEvent: () => isCanonicalWorldEvent,
|
|
45
|
+
isGossipTopicActive: () => isGossipTopicActive,
|
|
46
|
+
isGossipTopicCorrected: () => isGossipTopicCorrected,
|
|
47
|
+
isIncidentResolved: () => isIncidentResolved,
|
|
48
|
+
normalizeIncidentImpactVector: () => normalizeIncidentImpactVector,
|
|
49
|
+
packageDescriptor: () => packageDescriptor,
|
|
50
|
+
projectTopicForAudience: () => projectTopicForAudience,
|
|
51
|
+
resolveAiGamePlayerAddressText: () => resolveAiGamePlayerAddressText,
|
|
52
|
+
resolveAiGameTaskBatch: () => resolveAiGameTaskBatch
|
|
27
53
|
});
|
|
28
54
|
module.exports = __toCommonJS(index_exports);
|
|
55
|
+
|
|
56
|
+
// src/world-events.ts
|
|
57
|
+
function isCanonicalWorldEvent(event) {
|
|
58
|
+
return event.recordType === "canonical";
|
|
59
|
+
}
|
|
60
|
+
function isCandidateWorldEvent(event) {
|
|
61
|
+
return event.recordType === "candidate";
|
|
62
|
+
}
|
|
63
|
+
var WORLD_IMPACT_SCALE_LIMIT = 100;
|
|
64
|
+
function clampImpactValue(value) {
|
|
65
|
+
if (!Number.isFinite(value)) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
return Math.max(0, Math.min(WORLD_IMPACT_SCALE_LIMIT, value));
|
|
69
|
+
}
|
|
70
|
+
function normalizeIncidentImpactVector(impact) {
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
security: clampImpactValue(Number(impact.security ?? 0)),
|
|
73
|
+
economy: clampImpactValue(Number(impact.economy ?? 0)),
|
|
74
|
+
ecology: clampImpactValue(Number(impact.ecology ?? 0)),
|
|
75
|
+
politics: clampImpactValue(Number(impact.politics ?? 0)),
|
|
76
|
+
morale: clampImpactValue(Number(impact.morale ?? 0)),
|
|
77
|
+
magic: clampImpactValue(Number(impact.magic ?? 0)),
|
|
78
|
+
population: clampImpactValue(Number(impact.population ?? 0))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function isIncidentResolved(incident) {
|
|
82
|
+
return incident.lifecycle === "resolved" || incident.lifecycle === "expired";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/gossip.ts
|
|
86
|
+
function isGossipTopicActive(topic, nowEpochMs = Date.now()) {
|
|
87
|
+
return topic.status === "active" && topic.expiresAtEpochMs > nowEpochMs && topic.payload.certainty >= 0.35;
|
|
88
|
+
}
|
|
89
|
+
function isGossipTopicCorrected(topic) {
|
|
90
|
+
return topic.status === "corrected";
|
|
91
|
+
}
|
|
92
|
+
function matchSegmentAudience(sourceValue, targetValue, fallback) {
|
|
93
|
+
if (sourceValue.length === 0 || targetValue.length === 0) {
|
|
94
|
+
return fallback;
|
|
95
|
+
}
|
|
96
|
+
return sourceValue.some((value) => targetValue.includes(value));
|
|
97
|
+
}
|
|
98
|
+
function projectTopicForAudience(topic, projection, nowEpochMs = Date.now()) {
|
|
99
|
+
if (!isGossipTopicActive(topic, nowEpochMs)) {
|
|
100
|
+
return {
|
|
101
|
+
topicId: topic.topicId,
|
|
102
|
+
visible: false,
|
|
103
|
+
reasons: ["inactive-or-expired-topic"]
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const hasMatchingRule = projection.segmentRules.some(
|
|
107
|
+
(rule) => matchSegmentAudience(rule.locality, [projection.locality], true) && matchSegmentAudience(rule.factions, [projection.faction], false)
|
|
108
|
+
);
|
|
109
|
+
if (!hasMatchingRule) {
|
|
110
|
+
return {
|
|
111
|
+
topicId: topic.topicId,
|
|
112
|
+
visible: false,
|
|
113
|
+
reasons: ["audience-not-authorized"]
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (projection.projectionMode === "segment-level" && topic.audienceScope === "public") {
|
|
117
|
+
return {
|
|
118
|
+
topicId: topic.topicId,
|
|
119
|
+
visible: true,
|
|
120
|
+
redactedPayload: topic.payload,
|
|
121
|
+
reasons: ["segment-level-allowed"]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (projection.projectionMode === "npc-level" && projection.requestedByNpcRef && topic.audienceScope === "public" && projection.requestedByNpcRef.length > 0) {
|
|
125
|
+
return {
|
|
126
|
+
topicId: topic.topicId,
|
|
127
|
+
visible: true,
|
|
128
|
+
redactedPayload: topic.payload,
|
|
129
|
+
reasons: ["npc-level-allowed"]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (projection.projectionMode === "npc-level" && projection.requestedByNpcRef && topic.audienceScope !== "public" && projection.requestedByNpcRef.length > 0) {
|
|
133
|
+
return {
|
|
134
|
+
topicId: topic.topicId,
|
|
135
|
+
visible: true,
|
|
136
|
+
redactedPayload: topic.payload,
|
|
137
|
+
reasons: ["npc-level-allowed"]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
topicId: topic.topicId,
|
|
142
|
+
visible: false,
|
|
143
|
+
reasons: ["scope-constraints"]
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/index.ts
|
|
29
148
|
var AI_GAME_PACKAGE = "@plasius/ai-game";
|
|
30
|
-
var AI_GAME_FEATURE_FLAG_ID = "ai.game.enabled";
|
|
31
149
|
var AI_GAME_ENV_PREFIX = "AI_GAME";
|
|
150
|
+
var AI_GAME_FEATURE_FLAG_ID = "ai.game.enabled";
|
|
151
|
+
var AI_GAME_EVENT_CONTRACTS_FEATURE_FLAG_ID = "ai.game.event-recorder.contracts.enabled";
|
|
152
|
+
var AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID = "ai.game.event-recorder.ingestion.enabled";
|
|
153
|
+
var AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID = "ai.game.event-recorder.impact.enabled";
|
|
154
|
+
var AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID = "ai.game.npc-gossip.topics.enabled";
|
|
155
|
+
var AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID = "ai.game.npc-gossip.perspective.enabled";
|
|
156
|
+
var AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID = "ai.game.npc-gossip.lifecycle.enabled";
|
|
157
|
+
var AI_GAME_FEATURE_FLAGS = {
|
|
158
|
+
workloads: AI_GAME_FEATURE_FLAG_ID,
|
|
159
|
+
ttsCacheEnabled: "ai.tts.cache.enabled",
|
|
160
|
+
ttsNearReuseEnabled: "ai.tts.near-reuse.enabled"
|
|
161
|
+
};
|
|
162
|
+
var AI_GAME_TASK_KINDS = [
|
|
163
|
+
"player-action-validation",
|
|
164
|
+
"npc-action",
|
|
165
|
+
"npc-dialogue",
|
|
166
|
+
"gossip",
|
|
167
|
+
"governance-feedback",
|
|
168
|
+
"feedback",
|
|
169
|
+
"unknown"
|
|
170
|
+
];
|
|
171
|
+
var AI_GAME_TASK_RISK_CLASSES = [
|
|
172
|
+
"low",
|
|
173
|
+
"medium",
|
|
174
|
+
"high",
|
|
175
|
+
"critical"
|
|
176
|
+
];
|
|
177
|
+
var AI_GAME_TASK_AUTHORITY_BOUNDARIES = [
|
|
178
|
+
"deterministic",
|
|
179
|
+
"human-review",
|
|
180
|
+
"operator-review",
|
|
181
|
+
"blocked"
|
|
182
|
+
];
|
|
183
|
+
var AI_GAME_TASK_DECISIONS = ["allow", "operator-review", "blocked"];
|
|
184
|
+
var AI_GAME_TASK_RESULTS = ["allow", "defer", "deny"];
|
|
185
|
+
var AI_GAME_TTS_CACHE_POLICIES = [
|
|
186
|
+
"exact-cache",
|
|
187
|
+
"near-cache",
|
|
188
|
+
"no-cache"
|
|
189
|
+
];
|
|
190
|
+
var AI_GAME_ACTOR_ROLES = ["player", "npc", "operator", "system"];
|
|
191
|
+
var AI_GAME_TASK_PROFILE_BY_KIND = {
|
|
192
|
+
"player-action-validation": {
|
|
193
|
+
riskClass: "medium",
|
|
194
|
+
authorityBoundary: "human-review",
|
|
195
|
+
keywords: ["move", "attack", "collect", "use", "open", "pick", "trade", "target"]
|
|
196
|
+
},
|
|
197
|
+
"npc-action": {
|
|
198
|
+
riskClass: "high",
|
|
199
|
+
authorityBoundary: "operator-review",
|
|
200
|
+
keywords: ["summon", "kill", "ban", "spawn", "eject", "resurrect", "npc action", "npc-action"]
|
|
201
|
+
},
|
|
202
|
+
"npc-dialogue": {
|
|
203
|
+
riskClass: "low",
|
|
204
|
+
authorityBoundary: "deterministic",
|
|
205
|
+
keywords: ["say", "says", "reply", "chat", "dialogue", "greet", "warn", "request"]
|
|
206
|
+
},
|
|
207
|
+
gossip: {
|
|
208
|
+
riskClass: "high",
|
|
209
|
+
authorityBoundary: "operator-review",
|
|
210
|
+
keywords: ["rumor", "rumors", "gossip", "hearsay", "whisper", "spread", "denounce"]
|
|
211
|
+
},
|
|
212
|
+
"governance-feedback": {
|
|
213
|
+
riskClass: "critical",
|
|
214
|
+
authorityBoundary: "blocked",
|
|
215
|
+
keywords: ["punish", "expel", "revoke", "ban", "forbid", "seize"]
|
|
216
|
+
},
|
|
217
|
+
feedback: {
|
|
218
|
+
riskClass: "low",
|
|
219
|
+
authorityBoundary: "operator-review",
|
|
220
|
+
keywords: ["feedback", "rating", "report", "score", "review", "complaint"]
|
|
221
|
+
},
|
|
222
|
+
unknown: {
|
|
223
|
+
riskClass: "low",
|
|
224
|
+
authorityBoundary: "deterministic",
|
|
225
|
+
keywords: [""]
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var AI_GAME_TASK_KEYWORD_PATTERNS = {
|
|
229
|
+
"player-action-validation": buildTaskPattern(
|
|
230
|
+
AI_GAME_TASK_PROFILE_BY_KIND["player-action-validation"].keywords
|
|
231
|
+
),
|
|
232
|
+
"npc-action": buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND["npc-action"].keywords),
|
|
233
|
+
"npc-dialogue": buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND["npc-dialogue"].keywords),
|
|
234
|
+
gossip: buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND.gossip.keywords),
|
|
235
|
+
"governance-feedback": buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND["governance-feedback"].keywords),
|
|
236
|
+
feedback: buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND.feedback.keywords),
|
|
237
|
+
unknown: buildTaskPattern(AI_GAME_TASK_PROFILE_BY_KIND.unknown.keywords)
|
|
238
|
+
};
|
|
239
|
+
function nowIsoString() {
|
|
240
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
241
|
+
}
|
|
242
|
+
function escapeRegExp(value) {
|
|
243
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
244
|
+
}
|
|
245
|
+
function normalizeToken(value) {
|
|
246
|
+
return value.trim().replace(/\s+/g, " ");
|
|
247
|
+
}
|
|
248
|
+
function buildTaskPattern(keywords) {
|
|
249
|
+
return new RegExp(
|
|
250
|
+
keywords.filter((keyword) => keyword.length > 0).map((keyword) => `\\b${escapeRegExp(keyword)}\\b`).join("|") || "^$",
|
|
251
|
+
"i"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
function uniqueStrings(values) {
|
|
255
|
+
return Array.from(new Set(values.filter((value) => value.length > 0)));
|
|
256
|
+
}
|
|
257
|
+
function isFeatureEnabled(featureFlag, snapshot = {}) {
|
|
258
|
+
return snapshot[featureFlag] === true;
|
|
259
|
+
}
|
|
260
|
+
function normalizeTaskText(value) {
|
|
261
|
+
return value.trim().replace(/\s+/g, " ").toLowerCase();
|
|
262
|
+
}
|
|
263
|
+
function isActorRole(role) {
|
|
264
|
+
return role ?? "player";
|
|
265
|
+
}
|
|
266
|
+
function normalizeTaskKind(taskKind) {
|
|
267
|
+
if (!taskKind) {
|
|
268
|
+
return void 0;
|
|
269
|
+
}
|
|
270
|
+
return AI_GAME_TASK_KINDS.includes(taskKind) ? taskKind : "unknown";
|
|
271
|
+
}
|
|
272
|
+
function classifyAiGameTask(taskText) {
|
|
273
|
+
const normalized = normalizeTaskText(taskText);
|
|
274
|
+
if (!normalized) {
|
|
275
|
+
return "unknown";
|
|
276
|
+
}
|
|
277
|
+
for (const taskKind of AI_GAME_TASK_KINDS) {
|
|
278
|
+
if (AI_GAME_TASK_KEYWORD_PATTERNS[taskKind].test(normalized)) {
|
|
279
|
+
return taskKind;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return "unknown";
|
|
283
|
+
}
|
|
284
|
+
function resolveTaskAuthority(taskKind) {
|
|
285
|
+
return AI_GAME_TASK_PROFILE_BY_KIND[taskKind];
|
|
286
|
+
}
|
|
287
|
+
function resolveTaskDecision(taskKind, profile, actorRole) {
|
|
288
|
+
if (profile.authorityBoundary === "blocked") {
|
|
289
|
+
return {
|
|
290
|
+
decision: "blocked",
|
|
291
|
+
needsOperatorReview: actorRole !== "system"
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (profile.authorityBoundary === "deterministic") {
|
|
295
|
+
return {
|
|
296
|
+
decision: "allow",
|
|
297
|
+
needsOperatorReview: false
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
if (actorRole === "system") {
|
|
301
|
+
return {
|
|
302
|
+
decision: "allow",
|
|
303
|
+
needsOperatorReview: false
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
decision: "operator-review",
|
|
308
|
+
needsOperatorReview: true
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function buildRequestIds(requests) {
|
|
312
|
+
return uniqueStrings(requests.map((request) => request.taskId.trim()).filter(Boolean));
|
|
313
|
+
}
|
|
314
|
+
function resolveAiGameTaskBatch(input) {
|
|
315
|
+
const actorRole = isActorRole(input.actorRole);
|
|
316
|
+
const featureEnabled = isFeatureEnabled(
|
|
317
|
+
AI_GAME_FEATURE_FLAGS.workloads,
|
|
318
|
+
input.featureFlags
|
|
319
|
+
);
|
|
320
|
+
const reasonCodes = [...input.reasonCodes ?? []];
|
|
321
|
+
const requests = input.requests.map((request) => ({
|
|
322
|
+
...request,
|
|
323
|
+
taskKind: normalizeTaskKind(request.taskKind) ?? classifyAiGameTask(request.taskText)
|
|
324
|
+
}));
|
|
325
|
+
if (!featureEnabled) {
|
|
326
|
+
reasonCodes.push("game-feature-disabled");
|
|
327
|
+
const requestIds = buildRequestIds(requests);
|
|
328
|
+
return {
|
|
329
|
+
requestedTasks: requestIds,
|
|
330
|
+
taskDecisions: Object.freeze(
|
|
331
|
+
requestIds.map((taskId) => ({
|
|
332
|
+
taskId,
|
|
333
|
+
taskKind: "unknown",
|
|
334
|
+
riskClass: "critical",
|
|
335
|
+
authorityBoundary: "blocked",
|
|
336
|
+
decision: "blocked",
|
|
337
|
+
needsOperatorReview: false,
|
|
338
|
+
reasonCodes: ["feature-disabled"]
|
|
339
|
+
}))
|
|
340
|
+
),
|
|
341
|
+
allowedTaskIds: Object.freeze([]),
|
|
342
|
+
reviewTaskIds: Object.freeze([]),
|
|
343
|
+
blockedTaskIds: Object.freeze(requestIds),
|
|
344
|
+
needsOperatorReview: false,
|
|
345
|
+
featureEnabled,
|
|
346
|
+
enabledFeatureFlags: [],
|
|
347
|
+
source: "policy-disabled",
|
|
348
|
+
audit: {
|
|
349
|
+
policyId: input.policyId ?? "game-task-policy-v1",
|
|
350
|
+
policyVersion: input.policyVersion ?? "2026-05-01",
|
|
351
|
+
correlationId: input.correlationId ?? crypto.randomUUID(),
|
|
352
|
+
requestId: input.requestId,
|
|
353
|
+
actorId: input.actorId,
|
|
354
|
+
actorRole,
|
|
355
|
+
evaluatedAtUtc: nowIsoString(),
|
|
356
|
+
result: "deny"
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (requests.length === 0) {
|
|
361
|
+
reasonCodes.push("game-task-empty-request");
|
|
362
|
+
return {
|
|
363
|
+
requestedTasks: Object.freeze([]),
|
|
364
|
+
taskDecisions: Object.freeze([]),
|
|
365
|
+
allowedTaskIds: Object.freeze([]),
|
|
366
|
+
reviewTaskIds: Object.freeze([]),
|
|
367
|
+
blockedTaskIds: Object.freeze([]),
|
|
368
|
+
needsOperatorReview: false,
|
|
369
|
+
featureEnabled,
|
|
370
|
+
enabledFeatureFlags: [AI_GAME_FEATURE_FLAGS.workloads],
|
|
371
|
+
source: "policy-empty",
|
|
372
|
+
audit: {
|
|
373
|
+
policyId: input.policyId ?? "game-task-policy-v1",
|
|
374
|
+
policyVersion: input.policyVersion ?? "2026-05-01",
|
|
375
|
+
correlationId: input.correlationId ?? crypto.randomUUID(),
|
|
376
|
+
requestId: input.requestId,
|
|
377
|
+
actorId: input.actorId,
|
|
378
|
+
actorRole,
|
|
379
|
+
evaluatedAtUtc: nowIsoString(),
|
|
380
|
+
result: "allow"
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const taskDecisions = [];
|
|
385
|
+
for (const request of requests) {
|
|
386
|
+
const taskKind = request.taskKind;
|
|
387
|
+
const profile = resolveTaskAuthority(taskKind);
|
|
388
|
+
const decision = resolveTaskDecision(taskKind, profile, actorRole);
|
|
389
|
+
taskDecisions.push({
|
|
390
|
+
taskId: request.taskId,
|
|
391
|
+
taskKind,
|
|
392
|
+
riskClass: profile.riskClass,
|
|
393
|
+
authorityBoundary: profile.authorityBoundary,
|
|
394
|
+
...decision,
|
|
395
|
+
reasonCodes: [`task-${taskKind}-${decision.decision}`]
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
const allowedTaskIds = [];
|
|
399
|
+
const reviewTaskIds = [];
|
|
400
|
+
const blockedTaskIds = [];
|
|
401
|
+
for (const decision of taskDecisions) {
|
|
402
|
+
if (decision.decision === "allow") {
|
|
403
|
+
allowedTaskIds.push(decision.taskId);
|
|
404
|
+
} else if (decision.decision === "operator-review") {
|
|
405
|
+
reviewTaskIds.push(decision.taskId);
|
|
406
|
+
} else {
|
|
407
|
+
blockedTaskIds.push(decision.taskId);
|
|
408
|
+
}
|
|
409
|
+
reasonCodes.push(...decision.reasonCodes);
|
|
410
|
+
}
|
|
411
|
+
const hasBlockedTasks = blockedTaskIds.length > 0;
|
|
412
|
+
const needsOperatorReview = taskDecisions.some((decision) => decision.needsOperatorReview);
|
|
413
|
+
return {
|
|
414
|
+
requestedTasks: Object.freeze(buildRequestIds(requests)),
|
|
415
|
+
taskDecisions: Object.freeze(taskDecisions),
|
|
416
|
+
allowedTaskIds: Object.freeze(uniqueStrings(allowedTaskIds)),
|
|
417
|
+
reviewTaskIds: Object.freeze(uniqueStrings(reviewTaskIds)),
|
|
418
|
+
blockedTaskIds: Object.freeze(uniqueStrings(blockedTaskIds)),
|
|
419
|
+
needsOperatorReview,
|
|
420
|
+
featureEnabled,
|
|
421
|
+
enabledFeatureFlags: [AI_GAME_FEATURE_FLAGS.workloads],
|
|
422
|
+
source: "policy",
|
|
423
|
+
audit: {
|
|
424
|
+
policyId: input.policyId ?? "game-task-policy-v1",
|
|
425
|
+
policyVersion: input.policyVersion ?? "2026-05-01",
|
|
426
|
+
correlationId: input.correlationId ?? crypto.randomUUID(),
|
|
427
|
+
requestId: input.requestId,
|
|
428
|
+
actorId: input.actorId,
|
|
429
|
+
actorRole,
|
|
430
|
+
evaluatedAtUtc: nowIsoString(),
|
|
431
|
+
result: hasBlockedTasks ? "deny" : needsOperatorReview ? "defer" : "allow"
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function resolveAiGamePlayerAddressText(input) {
|
|
436
|
+
const actorRole = isActorRole(input.actorRole);
|
|
437
|
+
const cacheEnabled = isFeatureEnabled(
|
|
438
|
+
AI_GAME_FEATURE_FLAGS.ttsCacheEnabled,
|
|
439
|
+
input.featureFlags
|
|
440
|
+
);
|
|
441
|
+
const sourceText = normalizeToken(input.playerAddressText);
|
|
442
|
+
const reasonCodes = [...input.reasonCodes ?? []];
|
|
443
|
+
if (!sourceText) {
|
|
444
|
+
reasonCodes.push("tts-empty-text");
|
|
445
|
+
return {
|
|
446
|
+
sourceText,
|
|
447
|
+
renderText: "",
|
|
448
|
+
ttsCachePolicy: "no-cache",
|
|
449
|
+
reasonCodes,
|
|
450
|
+
enabledFeatureFlags: [],
|
|
451
|
+
source: "policy-empty",
|
|
452
|
+
audit: {
|
|
453
|
+
policyId: input.policyId ?? "game-task-policy-v1",
|
|
454
|
+
policyVersion: input.policyVersion ?? "2026-05-01",
|
|
455
|
+
correlationId: input.correlationId ?? crypto.randomUUID(),
|
|
456
|
+
requestId: input.requestId,
|
|
457
|
+
actorId: input.actorId,
|
|
458
|
+
actorRole,
|
|
459
|
+
evaluatedAtUtc: nowIsoString(),
|
|
460
|
+
cachePolicy: "no-cache"
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
const aliasEntries = [
|
|
465
|
+
...uniqueStrings([normalizeToken(input.playerAlias ?? "")]).filter(Boolean).map((alias) => ({
|
|
466
|
+
alias,
|
|
467
|
+
isAccountAlias: false
|
|
468
|
+
})),
|
|
469
|
+
...uniqueStrings([normalizeToken(input.accountAlias ?? "")]).filter(Boolean).map((alias) => ({
|
|
470
|
+
alias,
|
|
471
|
+
isAccountAlias: true
|
|
472
|
+
}))
|
|
473
|
+
];
|
|
474
|
+
let renderText = sourceText;
|
|
475
|
+
let replaced = false;
|
|
476
|
+
for (const alias of aliasEntries) {
|
|
477
|
+
const pattern = new RegExp(`\\b${escapeRegExp(alias.alias)}\\b`, "gi");
|
|
478
|
+
if (pattern.test(renderText)) {
|
|
479
|
+
renderText = renderText.replace(pattern, alias.isAccountAlias ? "[ACCOUNT]" : "[PLAYER]");
|
|
480
|
+
replaced = true;
|
|
481
|
+
reasonCodes.push(`tts-redacted-${alias.alias.toLowerCase()}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const nearCacheEnabled = isFeatureEnabled(
|
|
485
|
+
AI_GAME_FEATURE_FLAGS.ttsNearReuseEnabled,
|
|
486
|
+
input.featureFlags
|
|
487
|
+
);
|
|
488
|
+
if (!cacheEnabled) {
|
|
489
|
+
reasonCodes.push("tts-cache-disabled");
|
|
490
|
+
return {
|
|
491
|
+
sourceText,
|
|
492
|
+
renderText,
|
|
493
|
+
ttsCachePolicy: "no-cache",
|
|
494
|
+
reasonCodes,
|
|
495
|
+
enabledFeatureFlags: [],
|
|
496
|
+
source: "policy-disabled",
|
|
497
|
+
audit: {
|
|
498
|
+
policyId: input.policyId ?? "game-task-policy-v1",
|
|
499
|
+
policyVersion: input.policyVersion ?? "2026-05-01",
|
|
500
|
+
correlationId: input.correlationId ?? crypto.randomUUID(),
|
|
501
|
+
requestId: input.requestId,
|
|
502
|
+
actorId: input.actorId,
|
|
503
|
+
actorRole,
|
|
504
|
+
evaluatedAtUtc: nowIsoString(),
|
|
505
|
+
cachePolicy: "no-cache"
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
const cachePolicy = !replaced ? "exact-cache" : nearCacheEnabled ? "near-cache" : "no-cache";
|
|
510
|
+
if (cachePolicy === "exact-cache") {
|
|
511
|
+
reasonCodes.push("tts-cache-exact");
|
|
512
|
+
}
|
|
513
|
+
if (cachePolicy === "near-cache") {
|
|
514
|
+
reasonCodes.push("tts-cache-near");
|
|
515
|
+
}
|
|
516
|
+
if (cachePolicy === "no-cache") {
|
|
517
|
+
reasonCodes.push("tts-cache-not-available");
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
sourceText,
|
|
521
|
+
renderText,
|
|
522
|
+
ttsCachePolicy: cachePolicy,
|
|
523
|
+
reasonCodes,
|
|
524
|
+
enabledFeatureFlags: Object.freeze([
|
|
525
|
+
AI_GAME_FEATURE_FLAGS.workloads,
|
|
526
|
+
AI_GAME_FEATURE_FLAGS.ttsCacheEnabled,
|
|
527
|
+
...nearCacheEnabled ? [AI_GAME_FEATURE_FLAGS.ttsNearReuseEnabled] : []
|
|
528
|
+
]),
|
|
529
|
+
source: "policy",
|
|
530
|
+
audit: {
|
|
531
|
+
policyId: input.policyId ?? "game-task-policy-v1",
|
|
532
|
+
policyVersion: input.policyVersion ?? "2026-05-01",
|
|
533
|
+
correlationId: input.correlationId ?? crypto.randomUUID(),
|
|
534
|
+
requestId: input.requestId,
|
|
535
|
+
actorId: input.actorId,
|
|
536
|
+
actorRole,
|
|
537
|
+
evaluatedAtUtc: nowIsoString(),
|
|
538
|
+
cachePolicy
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
}
|
|
32
542
|
var packageDescriptor = Object.freeze({
|
|
33
543
|
packageName: AI_GAME_PACKAGE,
|
|
34
544
|
featureFlagId: AI_GAME_FEATURE_FLAG_ID,
|
|
35
545
|
envPrefix: AI_GAME_ENV_PREFIX,
|
|
36
|
-
summary: "Game-domain AI contracts for
|
|
546
|
+
summary: "Game-domain AI contracts for event recorder, canonical world-state, and NPC gossip projections."
|
|
547
|
+
});
|
|
548
|
+
var aiGameFeatureFlags = Object.freeze({
|
|
549
|
+
contract: AI_GAME_EVENT_CONTRACTS_FEATURE_FLAG_ID,
|
|
550
|
+
ingestion: AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID,
|
|
551
|
+
incident: AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID,
|
|
552
|
+
gossipTopics: AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID,
|
|
553
|
+
gossipPerspective: AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
|
|
554
|
+
gossipLifecycle: AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID
|
|
37
555
|
});
|
|
556
|
+
var gameEventFeatureFlags = Object.freeze([
|
|
557
|
+
aiGameFeatureFlags.contract,
|
|
558
|
+
aiGameFeatureFlags.ingestion,
|
|
559
|
+
aiGameFeatureFlags.incident,
|
|
560
|
+
aiGameFeatureFlags.gossipTopics,
|
|
561
|
+
aiGameFeatureFlags.gossipPerspective,
|
|
562
|
+
aiGameFeatureFlags.gossipLifecycle
|
|
563
|
+
]);
|
|
38
564
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
565
|
0 && (module.exports = {
|
|
566
|
+
AI_GAME_ACTOR_ROLES,
|
|
40
567
|
AI_GAME_ENV_PREFIX,
|
|
568
|
+
AI_GAME_EVENT_CONTRACTS_FEATURE_FLAG_ID,
|
|
569
|
+
AI_GAME_EVENT_INGESTION_FEATURE_FLAG_ID,
|
|
570
|
+
AI_GAME_FEATURE_FLAGS,
|
|
41
571
|
AI_GAME_FEATURE_FLAG_ID,
|
|
572
|
+
AI_GAME_GOSSIP_LIFECYCLE_FEATURE_FLAG_ID,
|
|
573
|
+
AI_GAME_GOSSIP_TOPICS_FEATURE_FLAG_ID,
|
|
574
|
+
AI_GAME_INCIDENT_IMPACT_FEATURE_FLAG_ID,
|
|
42
575
|
AI_GAME_PACKAGE,
|
|
43
|
-
|
|
576
|
+
AI_GAME_PERSPECTIVE_FEATURE_FLAG_ID,
|
|
577
|
+
AI_GAME_TASK_AUTHORITY_BOUNDARIES,
|
|
578
|
+
AI_GAME_TASK_DECISIONS,
|
|
579
|
+
AI_GAME_TASK_KINDS,
|
|
580
|
+
AI_GAME_TASK_RESULTS,
|
|
581
|
+
AI_GAME_TASK_RISK_CLASSES,
|
|
582
|
+
AI_GAME_TTS_CACHE_POLICIES,
|
|
583
|
+
aiGameFeatureFlags,
|
|
584
|
+
classifyAiGameTask,
|
|
585
|
+
gameEventFeatureFlags,
|
|
586
|
+
isCandidateWorldEvent,
|
|
587
|
+
isCanonicalWorldEvent,
|
|
588
|
+
isGossipTopicActive,
|
|
589
|
+
isGossipTopicCorrected,
|
|
590
|
+
isIncidentResolved,
|
|
591
|
+
normalizeIncidentImpactVector,
|
|
592
|
+
packageDescriptor,
|
|
593
|
+
projectTopicForAudience,
|
|
594
|
+
resolveAiGamePlayerAddressText,
|
|
595
|
+
resolveAiGameTaskBatch
|
|
44
596
|
});
|
|
45
597
|
//# sourceMappingURL=index.cjs.map
|