@sharpee/engine 0.9.64-beta → 0.9.66-beta
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/README.md +0 -0
- package/package.json +16 -34
- package/LICENSE +0 -21
- package/dist-npm/action-context-factory.d.ts +0 -11
- package/dist-npm/action-context-factory.d.ts.map +0 -1
- package/dist-npm/action-context-factory.js +0 -258
- package/dist-npm/action-context-factory.js.map +0 -1
- package/dist-npm/capability-dispatch-helper.d.ts +0 -106
- package/dist-npm/capability-dispatch-helper.d.ts.map +0 -1
- package/dist-npm/capability-dispatch-helper.js +0 -269
- package/dist-npm/capability-dispatch-helper.js.map +0 -1
- package/dist-npm/command-executor.d.ts +0 -53
- package/dist-npm/command-executor.d.ts.map +0 -1
- package/dist-npm/command-executor.js +0 -329
- package/dist-npm/command-executor.js.map +0 -1
- package/dist-npm/event-adapter.d.ts +0 -44
- package/dist-npm/event-adapter.d.ts.map +0 -1
- package/dist-npm/event-adapter.js +0 -127
- package/dist-npm/event-adapter.js.map +0 -1
- package/dist-npm/event-sequencer.d.ts +0 -73
- package/dist-npm/event-sequencer.d.ts.map +0 -1
- package/dist-npm/event-sequencer.js +0 -134
- package/dist-npm/event-sequencer.js.map +0 -1
- package/dist-npm/events/event-emitter.d.ts +0 -34
- package/dist-npm/events/event-emitter.d.ts.map +0 -1
- package/dist-npm/events/event-emitter.js +0 -67
- package/dist-npm/events/event-emitter.js.map +0 -1
- package/dist-npm/game-engine.d.ts +0 -292
- package/dist-npm/game-engine.d.ts.map +0 -1
- package/dist-npm/game-engine.js +0 -1597
- package/dist-npm/game-engine.js.map +0 -1
- package/dist-npm/index.d.ts +0 -27
- package/dist-npm/index.d.ts.map +0 -1
- package/dist-npm/index.js +0 -63
- package/dist-npm/index.js.map +0 -1
- package/dist-npm/narrative/index.d.ts +0 -5
- package/dist-npm/narrative/index.d.ts.map +0 -1
- package/dist-npm/narrative/index.js +0 -10
- package/dist-npm/narrative/index.js.map +0 -1
- package/dist-npm/narrative/narrative-settings.d.ts +0 -73
- package/dist-npm/narrative/narrative-settings.d.ts.map +0 -1
- package/dist-npm/narrative/narrative-settings.js +0 -28
- package/dist-npm/narrative/narrative-settings.js.map +0 -1
- package/dist-npm/parser-interface.d.ts +0 -77
- package/dist-npm/parser-interface.d.ts.map +0 -1
- package/dist-npm/parser-interface.js +0 -48
- package/dist-npm/parser-interface.js.map +0 -1
- package/dist-npm/platform-operations.d.ts +0 -83
- package/dist-npm/platform-operations.d.ts.map +0 -1
- package/dist-npm/platform-operations.js +0 -218
- package/dist-npm/platform-operations.js.map +0 -1
- package/dist-npm/save-restore-service.d.ts +0 -125
- package/dist-npm/save-restore-service.d.ts.map +0 -1
- package/dist-npm/save-restore-service.js +0 -405
- package/dist-npm/save-restore-service.js.map +0 -1
- package/dist-npm/scheduler/index.d.ts +0 -9
- package/dist-npm/scheduler/index.d.ts.map +0 -1
- package/dist-npm/scheduler/index.js +0 -25
- package/dist-npm/scheduler/index.js.map +0 -1
- package/dist-npm/scheduler/scheduler-service.d.ts +0 -75
- package/dist-npm/scheduler/scheduler-service.d.ts.map +0 -1
- package/dist-npm/scheduler/scheduler-service.js +0 -310
- package/dist-npm/scheduler/scheduler-service.js.map +0 -1
- package/dist-npm/scheduler/seeded-random.d.ts +0 -7
- package/dist-npm/scheduler/seeded-random.d.ts.map +0 -1
- package/dist-npm/scheduler/seeded-random.js +0 -11
- package/dist-npm/scheduler/seeded-random.js.map +0 -1
- package/dist-npm/scheduler/types.d.ts +0 -134
- package/dist-npm/scheduler/types.d.ts.map +0 -1
- package/dist-npm/scheduler/types.js +0 -9
- package/dist-npm/scheduler/types.js.map +0 -1
- package/dist-npm/shared-data-keys.d.ts +0 -53
- package/dist-npm/shared-data-keys.d.ts.map +0 -1
- package/dist-npm/shared-data-keys.js +0 -29
- package/dist-npm/shared-data-keys.js.map +0 -1
- package/dist-npm/story.d.ts +0 -216
- package/dist-npm/story.d.ts.map +0 -1
- package/dist-npm/story.js +0 -60
- package/dist-npm/story.js.map +0 -1
- package/dist-npm/test-helpers/mock-text-service.d.ts +0 -11
- package/dist-npm/test-helpers/mock-text-service.d.ts.map +0 -1
- package/dist-npm/test-helpers/mock-text-service.js +0 -47
- package/dist-npm/test-helpers/mock-text-service.js.map +0 -1
- package/dist-npm/turn-event-processor.d.ts +0 -89
- package/dist-npm/turn-event-processor.d.ts.map +0 -1
- package/dist-npm/turn-event-processor.js +0 -144
- package/dist-npm/turn-event-processor.js.map +0 -1
- package/dist-npm/types.d.ts +0 -214
- package/dist-npm/types.d.ts.map +0 -1
- package/dist-npm/types.js +0 -8
- package/dist-npm/types.js.map +0 -1
- package/dist-npm/vocabulary-manager.d.ts +0 -35
- package/dist-npm/vocabulary-manager.d.ts.map +0 -1
- package/dist-npm/vocabulary-manager.js +0 -74
- package/dist-npm/vocabulary-manager.js.map +0 -1
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Capability Dispatch Helper for Universal Dispatch
|
|
4
|
-
*
|
|
5
|
-
* Enables capability dispatch for ALL stdlib actions, not just specialized verbs.
|
|
6
|
-
* When an entity's trait declares a capability for an action, the trait's behavior
|
|
7
|
-
* handles the action instead of the stdlib default.
|
|
8
|
-
*
|
|
9
|
-
* This enables patterns like:
|
|
10
|
-
* - Troll blocking: TrollTrait handles 'if.action.going' to block passage
|
|
11
|
-
* - Custom containers: ChestTrait handles 'if.action.opening' for locked chest
|
|
12
|
-
* - Guardian items: AxeTrait handles 'if.action.taking' while troll guards it
|
|
13
|
-
*
|
|
14
|
-
* Resolution modes (ADR-090 extension):
|
|
15
|
-
* - first-wins: First entity with capability determines result
|
|
16
|
-
* - any-blocks: Any entity returning valid: false blocks
|
|
17
|
-
* - all-must-pass: All entities must return valid: true
|
|
18
|
-
* - highest-priority: Only highest priority entity is checked
|
|
19
|
-
*/
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.checkCapabilityDispatch = checkCapabilityDispatch;
|
|
22
|
-
exports.checkCapabilityDispatchMulti = checkCapabilityDispatchMulti;
|
|
23
|
-
exports.executeCapabilityValidate = executeCapabilityValidate;
|
|
24
|
-
exports.executeCapabilityExecute = executeCapabilityExecute;
|
|
25
|
-
exports.executeCapabilityReport = executeCapabilityReport;
|
|
26
|
-
exports.executeCapabilityBlocked = executeCapabilityBlocked;
|
|
27
|
-
const world_model_1 = require("../../world-model/dist-npm/src/index.js");
|
|
28
|
-
/**
|
|
29
|
-
* Check if capability dispatch should be used for this action and target.
|
|
30
|
-
*
|
|
31
|
-
* @param actionId - The action being executed
|
|
32
|
-
* @param target - The target entity (directObject) - for backward compatibility
|
|
33
|
-
* @returns Check result with trait and behavior if dispatch should be used
|
|
34
|
-
*/
|
|
35
|
-
function checkCapabilityDispatch(actionId, target) {
|
|
36
|
-
if (!target) {
|
|
37
|
-
return { shouldDispatch: false };
|
|
38
|
-
}
|
|
39
|
-
// Use the multi-entity version with single entity
|
|
40
|
-
return checkCapabilityDispatchMulti(actionId, [target]);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Check if capability dispatch should be used for this action across multiple entities.
|
|
44
|
-
*
|
|
45
|
-
* Collects all capability claims from the provided entities, sorts by priority,
|
|
46
|
-
* and returns the appropriate dispatch information based on resolution config.
|
|
47
|
-
*
|
|
48
|
-
* @param actionId - The action being executed
|
|
49
|
-
* @param entities - All entities involved in the action (directObject, indirectObject, etc.)
|
|
50
|
-
* @returns Check result with claims and resolution mode
|
|
51
|
-
*/
|
|
52
|
-
function checkCapabilityDispatchMulti(actionId, entities) {
|
|
53
|
-
const validEntities = entities.filter((e) => e !== undefined);
|
|
54
|
-
if (validEntities.length === 0) {
|
|
55
|
-
return { shouldDispatch: false };
|
|
56
|
-
}
|
|
57
|
-
// Collect all claims
|
|
58
|
-
const claims = [];
|
|
59
|
-
for (const entity of validEntities) {
|
|
60
|
-
const trait = (0, world_model_1.findTraitWithCapability)(entity, actionId);
|
|
61
|
-
if (!trait)
|
|
62
|
-
continue;
|
|
63
|
-
const binding = (0, world_model_1.getBehaviorBinding)(trait, actionId);
|
|
64
|
-
if (!binding) {
|
|
65
|
-
// Trait claims capability but no behavior registered
|
|
66
|
-
console.warn(`Universal dispatch: trait "${trait.type}" claims "${actionId}" ` +
|
|
67
|
-
`but no behavior registered. Falling back to stdlib action.`);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
claims.push({
|
|
71
|
-
entity,
|
|
72
|
-
trait,
|
|
73
|
-
behavior: binding.behavior,
|
|
74
|
-
priority: binding.priority,
|
|
75
|
-
resolutionOverride: binding.resolution
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (claims.length === 0) {
|
|
79
|
-
return { shouldDispatch: false };
|
|
80
|
-
}
|
|
81
|
-
// Sort by priority (highest first)
|
|
82
|
-
claims.sort((a, b) => b.priority - a.priority);
|
|
83
|
-
// Get resolution mode (use first binding override if present, else global config)
|
|
84
|
-
const firstOverride = claims.find(c => c.resolutionOverride)?.resolutionOverride;
|
|
85
|
-
const config = (0, world_model_1.getCapabilityConfig)(actionId);
|
|
86
|
-
const resolution = firstOverride ?? config.resolution;
|
|
87
|
-
// For single claim or first-wins/highest-priority, return simple result
|
|
88
|
-
if (claims.length === 1 || resolution === 'first-wins' || resolution === 'highest-priority') {
|
|
89
|
-
const primary = claims[0];
|
|
90
|
-
return {
|
|
91
|
-
shouldDispatch: true,
|
|
92
|
-
trait: primary.trait,
|
|
93
|
-
behavior: primary.behavior,
|
|
94
|
-
entity: primary.entity,
|
|
95
|
-
claims,
|
|
96
|
-
resolution
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
// For any-blocks or all-must-pass, return all claims for aggregate validation
|
|
100
|
-
return {
|
|
101
|
-
shouldDispatch: true,
|
|
102
|
-
trait: claims[0].trait,
|
|
103
|
-
behavior: claims[0].behavior,
|
|
104
|
-
entity: claims[0].entity,
|
|
105
|
-
claims,
|
|
106
|
-
resolution
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Convert capability effects to semantic events.
|
|
111
|
-
*/
|
|
112
|
-
function effectsToEvents(effects, context) {
|
|
113
|
-
return effects.map(effect => context.event(effect.type, effect.payload));
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Execute capability dispatch validation phase.
|
|
117
|
-
*
|
|
118
|
-
* Handles resolution modes:
|
|
119
|
-
* - first-wins/highest-priority: Single behavior validates
|
|
120
|
-
* - any-blocks: All behaviors validate, any false blocks
|
|
121
|
-
* - all-must-pass: All behaviors must return true
|
|
122
|
-
*
|
|
123
|
-
* @returns ValidationResult with dispatch data if valid
|
|
124
|
-
*/
|
|
125
|
-
function executeCapabilityValidate(check, context) {
|
|
126
|
-
const { trait, behavior, entity, claims, resolution } = check;
|
|
127
|
-
if (!trait || !behavior || !entity) {
|
|
128
|
-
return { valid: false, error: 'capability_dispatch_error' };
|
|
129
|
-
}
|
|
130
|
-
// Create sharedData for passing data between behavior phases
|
|
131
|
-
const sharedData = {};
|
|
132
|
-
// For first-wins or highest-priority (or single claim), just validate the primary
|
|
133
|
-
if (!claims || claims.length <= 1 || resolution === 'first-wins' || resolution === 'highest-priority') {
|
|
134
|
-
return validateSingleBehavior(entity, trait, behavior, context, sharedData);
|
|
135
|
-
}
|
|
136
|
-
// For any-blocks: validate all, return first failure
|
|
137
|
-
if (resolution === 'any-blocks') {
|
|
138
|
-
for (const claim of claims) {
|
|
139
|
-
const claimSharedData = {};
|
|
140
|
-
const result = claim.behavior.validate(claim.entity, context.world, context.player.id, claimSharedData);
|
|
141
|
-
if (!result.valid) {
|
|
142
|
-
// This claim blocks - use its error
|
|
143
|
-
const data = {
|
|
144
|
-
trait: claim.trait,
|
|
145
|
-
behavior: claim.behavior,
|
|
146
|
-
entityId: claim.entity.id,
|
|
147
|
-
entityName: claim.entity.name,
|
|
148
|
-
sharedData: claimSharedData
|
|
149
|
-
};
|
|
150
|
-
return {
|
|
151
|
-
valid: false,
|
|
152
|
-
error: result.error,
|
|
153
|
-
params: result.params,
|
|
154
|
-
data
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
// All passed - use primary for execute/report
|
|
159
|
-
const data = {
|
|
160
|
-
trait,
|
|
161
|
-
behavior,
|
|
162
|
-
entityId: entity.id,
|
|
163
|
-
entityName: entity.name,
|
|
164
|
-
sharedData
|
|
165
|
-
};
|
|
166
|
-
return { valid: true, data };
|
|
167
|
-
}
|
|
168
|
-
// For all-must-pass: same logic as any-blocks (any failure = overall failure)
|
|
169
|
-
if (resolution === 'all-must-pass') {
|
|
170
|
-
for (const claim of claims) {
|
|
171
|
-
const claimSharedData = {};
|
|
172
|
-
const result = claim.behavior.validate(claim.entity, context.world, context.player.id, claimSharedData);
|
|
173
|
-
if (!result.valid) {
|
|
174
|
-
const data = {
|
|
175
|
-
trait: claim.trait,
|
|
176
|
-
behavior: claim.behavior,
|
|
177
|
-
entityId: claim.entity.id,
|
|
178
|
-
entityName: claim.entity.name,
|
|
179
|
-
sharedData: claimSharedData
|
|
180
|
-
};
|
|
181
|
-
return {
|
|
182
|
-
valid: false,
|
|
183
|
-
error: result.error,
|
|
184
|
-
params: result.params,
|
|
185
|
-
data
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const data = {
|
|
190
|
-
trait,
|
|
191
|
-
behavior,
|
|
192
|
-
entityId: entity.id,
|
|
193
|
-
entityName: entity.name,
|
|
194
|
-
sharedData
|
|
195
|
-
};
|
|
196
|
-
return { valid: true, data };
|
|
197
|
-
}
|
|
198
|
-
// Default: first-wins fallback
|
|
199
|
-
return validateSingleBehavior(entity, trait, behavior, context, sharedData);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Validate a single behavior (helper for executeCapabilityValidate).
|
|
203
|
-
*/
|
|
204
|
-
function validateSingleBehavior(entity, trait, behavior, context, sharedData) {
|
|
205
|
-
const behaviorResult = behavior.validate(entity, context.world, context.player.id, sharedData);
|
|
206
|
-
const data = {
|
|
207
|
-
trait,
|
|
208
|
-
behavior,
|
|
209
|
-
entityId: entity.id,
|
|
210
|
-
entityName: entity.name,
|
|
211
|
-
sharedData
|
|
212
|
-
};
|
|
213
|
-
if (!behaviorResult.valid) {
|
|
214
|
-
return {
|
|
215
|
-
valid: false,
|
|
216
|
-
error: behaviorResult.error,
|
|
217
|
-
params: behaviorResult.params,
|
|
218
|
-
data
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
return { valid: true, data };
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Execute capability dispatch execute phase.
|
|
225
|
-
*/
|
|
226
|
-
function executeCapabilityExecute(context) {
|
|
227
|
-
const data = context.validationResult?.data;
|
|
228
|
-
const entity = context.command.directObject?.entity;
|
|
229
|
-
if (!entity || !data?.behavior) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
// Delegate execution to behavior
|
|
233
|
-
data.behavior.execute(entity, context.world, context.player.id, data.sharedData);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Execute capability dispatch report phase.
|
|
237
|
-
*/
|
|
238
|
-
function executeCapabilityReport(context) {
|
|
239
|
-
const data = context.validationResult?.data;
|
|
240
|
-
const entity = context.command.directObject?.entity;
|
|
241
|
-
if (!entity || !data?.behavior) {
|
|
242
|
-
return [];
|
|
243
|
-
}
|
|
244
|
-
// Delegate reporting to behavior
|
|
245
|
-
const effects = data.behavior.report(entity, context.world, context.player.id, data.sharedData);
|
|
246
|
-
return effectsToEvents(effects, context);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Execute capability dispatch blocked phase.
|
|
250
|
-
*/
|
|
251
|
-
function executeCapabilityBlocked(context, result, actionId) {
|
|
252
|
-
// Check both validationResult.data and result.data
|
|
253
|
-
const data = (context.validationResult?.data ?? result.data);
|
|
254
|
-
const entity = context.command.directObject?.entity;
|
|
255
|
-
// If we have a behavior, let it handle the blocked message
|
|
256
|
-
if (entity && data?.behavior) {
|
|
257
|
-
const effects = data.behavior.blocked(entity, context.world, context.player.id, result.error || 'action_blocked', data.sharedData);
|
|
258
|
-
return effectsToEvents(effects, context);
|
|
259
|
-
}
|
|
260
|
-
// Default blocked event (shouldn't normally reach here)
|
|
261
|
-
return [
|
|
262
|
-
context.event('action.blocked', {
|
|
263
|
-
actionId,
|
|
264
|
-
messageId: result.error || 'action_blocked',
|
|
265
|
-
params: result.params || {}
|
|
266
|
-
})
|
|
267
|
-
];
|
|
268
|
-
}
|
|
269
|
-
//# sourceMappingURL=capability-dispatch-helper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capability-dispatch-helper.js","sourceRoot":"","sources":["../../../../src/capability-dispatch-helper.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAsEH,0DAUC;AAYD,oEAsEC;AAsBD,8DAoGC;AA0CD,4DAYC;AAKD,0DAkBC;AAKD,4DA6BC;AAxYD,sDAY8B;AAgD9B;;;;;;GAMG;AACH,SAAgB,uBAAuB,CACrC,QAAgB,EAChB,MAA4B;IAE5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IAED,kDAAkD;IAClD,OAAO,4BAA4B,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,4BAA4B,CAC1C,QAAgB,EAChB,QAAkC;IAElC,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAiB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAE7E,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IAED,qBAAqB;IACrB,MA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CAAC,MAAM,CAClC,MAAM,EACN,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,MAAM,CAAC,EAAE,EACjB,IAAI,CAAC,UAAU,CAChB,CAAC;IACF,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CACtC,OAAsB,EACtB,MAAwB,EACxB,QAAgB;IAEhB,mDAAmD;IACnD,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,IAAI,MAAM,CAAC,IAAI,CAAuC,CAAC;IACnG,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;IAEpD,2DAA2D;IAC3D,IAAI,MAAM,IAAI,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CACnC,MAAM,EACN,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,MAAM,CAAC,EAAE,EACjB,MAAM,CAAC,KAAK,IAAI,gBAAgB,EAChC,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,wDAAwD;IACxD,OAAO;QACL,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE;YAC9B,QAAQ;YACR,SAAS,EAAE,MAAM,CAAC,KAAK,IAAI,gBAAgB;YAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;SAC5B,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Command Executor - Orchestrates command pipeline
|
|
3
|
-
*
|
|
4
|
-
* Responsibilities:
|
|
5
|
-
* - Orchestrate the four-phase pattern (validate → execute → report/blocked)
|
|
6
|
-
* - Handle implicit inference (ADR-104) when validation fails with pronouns
|
|
7
|
-
* - Pass results between phases
|
|
8
|
-
* - Return the final TurnResult
|
|
9
|
-
*
|
|
10
|
-
* All event creation is owned by the action components themselves.
|
|
11
|
-
*/
|
|
12
|
-
import { ISystemEvent, IGenericEventSource } from "../../core/dist-npm/src/index";
|
|
13
|
-
import { IParser, IParsedCommand } from "../../world-model/dist-npm/src/index";
|
|
14
|
-
import { WorldModel } from "../../world-model/dist-npm/src/index";
|
|
15
|
-
import { EventProcessor } from "../../event-processor/dist-npm/src/index";
|
|
16
|
-
import { ActionRegistry } from "../../stdlib/dist-npm/src/index";
|
|
17
|
-
import { GameContext, TurnResult, EngineConfig } from './types';
|
|
18
|
-
/**
|
|
19
|
-
* Transformer function for parsed commands.
|
|
20
|
-
* Called after parsing but before validation.
|
|
21
|
-
* Can modify the parsed command to bypass or alter validation behavior.
|
|
22
|
-
*
|
|
23
|
-
* @param parsed - The parsed command from the parser
|
|
24
|
-
* @param world - The world model for checking state (e.g., gdtMode)
|
|
25
|
-
* @returns The (potentially modified) parsed command
|
|
26
|
-
*/
|
|
27
|
-
export type ParsedCommandTransformer = (parsed: IParsedCommand, world: WorldModel) => IParsedCommand;
|
|
28
|
-
export declare class CommandExecutor {
|
|
29
|
-
private parser;
|
|
30
|
-
private validator;
|
|
31
|
-
private actionRegistry;
|
|
32
|
-
private eventProcessor;
|
|
33
|
-
private scopeResolver?;
|
|
34
|
-
private parsedCommandTransformers;
|
|
35
|
-
constructor(world: WorldModel, actionRegistry: ActionRegistry, eventProcessor: EventProcessor, parser: IParser, systemEvents?: IGenericEventSource<ISystemEvent>);
|
|
36
|
-
/**
|
|
37
|
-
* Register a transformer that can modify parsed commands before validation.
|
|
38
|
-
* Transformers are called in order of registration.
|
|
39
|
-
*
|
|
40
|
-
* @param transformer - Function to transform parsed commands
|
|
41
|
-
*/
|
|
42
|
-
registerParsedCommandTransformer(transformer: ParsedCommandTransformer): void;
|
|
43
|
-
/**
|
|
44
|
-
* Unregister a previously registered transformer.
|
|
45
|
-
*
|
|
46
|
-
* @param transformer - The transformer to remove
|
|
47
|
-
* @returns true if the transformer was found and removed
|
|
48
|
-
*/
|
|
49
|
-
unregisterParsedCommandTransformer(transformer: ParsedCommandTransformer): boolean;
|
|
50
|
-
execute(input: string, world: WorldModel, context: GameContext, config?: EngineConfig): Promise<TurnResult>;
|
|
51
|
-
}
|
|
52
|
-
export declare function createCommandExecutor(world: WorldModel, actionRegistry: ActionRegistry, eventProcessor: EventProcessor, parser: IParser, systemEvents?: IGenericEventSource<ISystemEvent>): CommandExecutor;
|
|
53
|
-
//# sourceMappingURL=command-executor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-executor.d.ts","sourceRoot":"","sources":["../../../../src/command-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAkB,YAAY,EAAE,mBAAmB,EAA0B,MAAM,eAAe,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAqB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGlF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAEL,cAAc,EAKf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYhE;;;;;;;;GAQG;AACH,MAAM,MAAM,wBAAwB,GAAG,CACrC,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,UAAU,KACd,cAAc,CAAC;AAEpB,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,OAAO,CAAC,yBAAyB,CAAkC;gBAGjE,KAAK,EAAE,UAAU,EACjB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,OAAO,EACf,YAAY,CAAC,EAAE,mBAAmB,CAAC,YAAY,CAAC;IAgBlD;;;;;OAKG;IACH,gCAAgC,CAAC,WAAW,EAAE,wBAAwB,GAAG,IAAI;IAI7E;;;;;OAKG;IACH,kCAAkC,CAAC,WAAW,EAAE,wBAAwB,GAAG,OAAO;IAS5E,OAAO,CACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,UAAU,CAAC;CA4SvB;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,UAAU,EACjB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,OAAO,EACf,YAAY,CAAC,EAAE,mBAAmB,CAAC,YAAY,CAAC,GAC/C,eAAe,CAEjB"}
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Command Executor - Orchestrates command pipeline
|
|
4
|
-
*
|
|
5
|
-
* Responsibilities:
|
|
6
|
-
* - Orchestrate the four-phase pattern (validate → execute → report/blocked)
|
|
7
|
-
* - Handle implicit inference (ADR-104) when validation fails with pronouns
|
|
8
|
-
* - Pass results between phases
|
|
9
|
-
* - Return the final TurnResult
|
|
10
|
-
*
|
|
11
|
-
* All event creation is owned by the action components themselves.
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.CommandExecutor = void 0;
|
|
15
|
-
exports.createCommandExecutor = createCommandExecutor;
|
|
16
|
-
const core_1 = require("../../core/dist-npm/src/index.js");
|
|
17
|
-
const parser_interface_1 = require("./parser-interface");
|
|
18
|
-
const shared_data_keys_1 = require("./shared-data-keys");
|
|
19
|
-
const stdlib_1 = require("../../stdlib/dist-npm/src/index.js");
|
|
20
|
-
const event_sequencer_1 = require("./event-sequencer");
|
|
21
|
-
const action_context_factory_1 = require("./action-context-factory");
|
|
22
|
-
const capability_dispatch_helper_1 = require("./capability-dispatch-helper");
|
|
23
|
-
class CommandExecutor {
|
|
24
|
-
parser;
|
|
25
|
-
validator;
|
|
26
|
-
actionRegistry;
|
|
27
|
-
eventProcessor;
|
|
28
|
-
scopeResolver;
|
|
29
|
-
parsedCommandTransformers = [];
|
|
30
|
-
constructor(world, actionRegistry, eventProcessor, parser, systemEvents) {
|
|
31
|
-
if (!world)
|
|
32
|
-
throw new Error('World model is required');
|
|
33
|
-
if (!actionRegistry)
|
|
34
|
-
throw new Error('Action registry is required');
|
|
35
|
-
if (!eventProcessor)
|
|
36
|
-
throw new Error('Event processor is required');
|
|
37
|
-
if (!parser)
|
|
38
|
-
throw new Error('Parser is required');
|
|
39
|
-
this.parser = parser;
|
|
40
|
-
this.validator = new stdlib_1.CommandValidator(world, actionRegistry);
|
|
41
|
-
if (systemEvents) {
|
|
42
|
-
this.validator.setSystemEventSource(systemEvents);
|
|
43
|
-
}
|
|
44
|
-
this.actionRegistry = actionRegistry;
|
|
45
|
-
this.eventProcessor = eventProcessor;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Register a transformer that can modify parsed commands before validation.
|
|
49
|
-
* Transformers are called in order of registration.
|
|
50
|
-
*
|
|
51
|
-
* @param transformer - Function to transform parsed commands
|
|
52
|
-
*/
|
|
53
|
-
registerParsedCommandTransformer(transformer) {
|
|
54
|
-
this.parsedCommandTransformers.push(transformer);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Unregister a previously registered transformer.
|
|
58
|
-
*
|
|
59
|
-
* @param transformer - The transformer to remove
|
|
60
|
-
* @returns true if the transformer was found and removed
|
|
61
|
-
*/
|
|
62
|
-
unregisterParsedCommandTransformer(transformer) {
|
|
63
|
-
const index = this.parsedCommandTransformers.indexOf(transformer);
|
|
64
|
-
if (index !== -1) {
|
|
65
|
-
this.parsedCommandTransformers.splice(index, 1);
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
async execute(input, world, context, config) {
|
|
71
|
-
const turn = context.currentTurn;
|
|
72
|
-
event_sequencer_1.eventSequencer.resetTurn(turn);
|
|
73
|
-
// Timing tracking
|
|
74
|
-
const startTime = config?.collectTiming ? Date.now() : 0;
|
|
75
|
-
let parseTime = 0;
|
|
76
|
-
let executionTime = 0;
|
|
77
|
-
try {
|
|
78
|
-
// Set world context for parser entity resolution
|
|
79
|
-
const player = world.getPlayer();
|
|
80
|
-
if (player && (0, parser_interface_1.hasWorldContext)(this.parser)) {
|
|
81
|
-
const playerLocation = world.getLocation(player.id) || '';
|
|
82
|
-
this.parser.setWorldContext(world, player.id, playerLocation);
|
|
83
|
-
}
|
|
84
|
-
// Phase 1: Parse
|
|
85
|
-
const parseStart = config?.collectTiming ? Date.now() : 0;
|
|
86
|
-
const parseResult = this.parser.parse(input);
|
|
87
|
-
if (config?.collectTiming) {
|
|
88
|
-
parseTime = Date.now() - parseStart;
|
|
89
|
-
}
|
|
90
|
-
if (!parseResult.success) {
|
|
91
|
-
throw new Error(`Parse failed: ${parseResult.error.code}`);
|
|
92
|
-
}
|
|
93
|
-
// Phase 1.5: Apply parsed command transformers
|
|
94
|
-
// Allows stories to modify parsed commands before validation
|
|
95
|
-
let parsedCommand = parseResult.value;
|
|
96
|
-
for (const transformer of this.parsedCommandTransformers) {
|
|
97
|
-
parsedCommand = transformer(parsedCommand, world);
|
|
98
|
-
}
|
|
99
|
-
// Phase 2: Validate
|
|
100
|
-
const validationResult = this.validator.validate(parsedCommand);
|
|
101
|
-
if (!validationResult.success) {
|
|
102
|
-
// Check for disambiguation - emit client.query event instead of throwing
|
|
103
|
-
if (validationResult.error.code === 'AMBIGUOUS_ENTITY') {
|
|
104
|
-
const details = validationResult.error.details || {};
|
|
105
|
-
const candidates = details.ambiguousEntities || [];
|
|
106
|
-
// Emit client.query event for disambiguation
|
|
107
|
-
const queryEvent = event_sequencer_1.eventSequencer.sequence({
|
|
108
|
-
type: 'client.query',
|
|
109
|
-
data: {
|
|
110
|
-
source: core_1.QuerySource.DISAMBIGUATION,
|
|
111
|
-
type: core_1.QueryType.DISAMBIGUATION,
|
|
112
|
-
messageId: 'core.disambiguation_prompt',
|
|
113
|
-
candidates: candidates,
|
|
114
|
-
searchText: details.searchText,
|
|
115
|
-
originalCommand: parsedCommand
|
|
116
|
-
}
|
|
117
|
-
}, turn);
|
|
118
|
-
// Return early with query pending
|
|
119
|
-
return {
|
|
120
|
-
turn,
|
|
121
|
-
input,
|
|
122
|
-
success: false,
|
|
123
|
-
needsInput: true,
|
|
124
|
-
events: [queryEvent],
|
|
125
|
-
error: 'DISAMBIGUATION_NEEDED'
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
// Other validation errors still throw
|
|
129
|
-
throw new Error(`Validation failed: ${validationResult.error.code}`);
|
|
130
|
-
}
|
|
131
|
-
// Phase 3: Execute action's three-phase pattern
|
|
132
|
-
const executionStart = config?.collectTiming ? Date.now() : 0;
|
|
133
|
-
const command = validationResult.value;
|
|
134
|
-
const action = this.actionRegistry.get(command.actionId);
|
|
135
|
-
if (!action) {
|
|
136
|
-
throw new Error(`Action not found: ${command.actionId}`);
|
|
137
|
-
}
|
|
138
|
-
// Create context
|
|
139
|
-
if (!this.scopeResolver) {
|
|
140
|
-
this.scopeResolver = (0, stdlib_1.createScopeResolver)(world);
|
|
141
|
-
}
|
|
142
|
-
const actionContext = (0, action_context_factory_1.createActionContext)(world, context, command, action, this.scopeResolver);
|
|
143
|
-
// Universal Capability Dispatch: Check if any involved entity has a capability for this action
|
|
144
|
-
// If so, the entity's behavior handles the action instead of the stdlib default
|
|
145
|
-
// Check all entities: directObject, indirectObject, and any others
|
|
146
|
-
const involvedEntities = [
|
|
147
|
-
command.directObject?.entity,
|
|
148
|
-
command.indirectObject?.entity
|
|
149
|
-
];
|
|
150
|
-
const capabilityCheck = (0, capability_dispatch_helper_1.checkCapabilityDispatchMulti)(command.actionId, involvedEntities);
|
|
151
|
-
// Run action's four phases: validate → execute → report (or blocked)
|
|
152
|
-
// If capability dispatch applies, use capability behavior; otherwise use action
|
|
153
|
-
let actionValidation = capabilityCheck.shouldDispatch
|
|
154
|
-
? (0, capability_dispatch_helper_1.executeCapabilityValidate)(capabilityCheck, actionContext)
|
|
155
|
-
: action.validate(actionContext);
|
|
156
|
-
let currentCommand = command;
|
|
157
|
-
let currentContext = actionContext;
|
|
158
|
-
let useCapabilityDispatch = capabilityCheck.shouldDispatch;
|
|
159
|
-
// ADR-104: Implicit inference - if validation fails and pronoun was used,
|
|
160
|
-
// try to find a valid alternative target
|
|
161
|
-
// Check story-level config first
|
|
162
|
-
const inferenceEnabled = context.implicitActions?.inference !== false;
|
|
163
|
-
if (!actionValidation.valid && action.targetRequirements && inferenceEnabled) {
|
|
164
|
-
const directObject = command.directObject;
|
|
165
|
-
// Check if pronoun was used (INounPhrase has wasPronoun, cast is safe)
|
|
166
|
-
const parsedNounPhrase = directObject?.parsed;
|
|
167
|
-
const wasPronoun = parsedNounPhrase?.wasPronoun === true;
|
|
168
|
-
if (wasPronoun && directObject?.entity) {
|
|
169
|
-
// Note: directObject.parsed is typed as IParsedObjectReference but at runtime
|
|
170
|
-
// it's actually an INounPhrase (command-validator sets it from the noun phrase)
|
|
171
|
-
// Get entities in scope for inference (visible entities)
|
|
172
|
-
const scopeEntities = this.scopeResolver.getVisible(world.getPlayer());
|
|
173
|
-
// Try to infer a different target
|
|
174
|
-
const inferenceResult = (0, stdlib_1.tryInferTarget)(directObject.entity, wasPronoun, action, scopeEntities, world);
|
|
175
|
-
if (inferenceResult.inferred && inferenceResult.inferredTarget) {
|
|
176
|
-
// Create a modified command with the inferred target
|
|
177
|
-
const inferredCommand = {
|
|
178
|
-
...command,
|
|
179
|
-
directObject: {
|
|
180
|
-
entity: inferenceResult.inferredTarget,
|
|
181
|
-
parsed: {
|
|
182
|
-
...directObject.parsed,
|
|
183
|
-
// Update text to reflect inferred entity
|
|
184
|
-
text: inferenceResult.inferredTarget.name
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
// Create new context with inferred command
|
|
189
|
-
const inferredContext = (0, action_context_factory_1.createActionContext)(world, context, inferredCommand, action, this.scopeResolver);
|
|
190
|
-
// Mark that inference occurred (for "(the leaflet)" message)
|
|
191
|
-
const sharedData = inferredContext.sharedData;
|
|
192
|
-
sharedData[shared_data_keys_1.SharedDataKeys.INFERENCE_PERFORMED] = true;
|
|
193
|
-
sharedData[shared_data_keys_1.SharedDataKeys.ORIGINAL_TARGET] = directObject.entity;
|
|
194
|
-
sharedData[shared_data_keys_1.SharedDataKeys.INFERRED_TARGET] = inferenceResult.inferredTarget;
|
|
195
|
-
// Re-check capability dispatch for inferred target
|
|
196
|
-
const inferredInvolvedEntities = [
|
|
197
|
-
inferenceResult.inferredTarget,
|
|
198
|
-
command.indirectObject?.entity
|
|
199
|
-
];
|
|
200
|
-
const inferredCapabilityCheck = (0, capability_dispatch_helper_1.checkCapabilityDispatchMulti)(command.actionId, inferredInvolvedEntities);
|
|
201
|
-
// Re-validate with inferred target (using capability dispatch if applicable)
|
|
202
|
-
const retryValidation = inferredCapabilityCheck.shouldDispatch
|
|
203
|
-
? (0, capability_dispatch_helper_1.executeCapabilityValidate)(inferredCapabilityCheck, inferredContext)
|
|
204
|
-
: action.validate(inferredContext);
|
|
205
|
-
if (retryValidation.valid) {
|
|
206
|
-
// Inference succeeded - use the inferred command
|
|
207
|
-
actionValidation = retryValidation;
|
|
208
|
-
currentCommand = inferredCommand;
|
|
209
|
-
currentContext = inferredContext;
|
|
210
|
-
useCapabilityDispatch = inferredCapabilityCheck.shouldDispatch;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// Thread validation result to later phases via context
|
|
216
|
-
// This allows actions to access data from validate() in execute/report
|
|
217
|
-
currentContext.validationResult = actionValidation;
|
|
218
|
-
let events;
|
|
219
|
-
if (actionValidation.valid) {
|
|
220
|
-
if (useCapabilityDispatch) {
|
|
221
|
-
// Capability dispatch: use behavior phases
|
|
222
|
-
(0, capability_dispatch_helper_1.executeCapabilityExecute)(currentContext);
|
|
223
|
-
events = (0, capability_dispatch_helper_1.executeCapabilityReport)(currentContext);
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
// Standard action: use action phases
|
|
227
|
-
const executeResult = action.execute(currentContext);
|
|
228
|
-
// Check pattern (new vs old)
|
|
229
|
-
if (executeResult === undefined || executeResult === null) {
|
|
230
|
-
// New pattern: use report() for success events only
|
|
231
|
-
if (action.report) {
|
|
232
|
-
events = action.report(currentContext);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
throw new Error(`Action ${action.id} uses new pattern but lacks report()`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
// Old pattern: events from execute()
|
|
240
|
-
events = executeResult;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
// Validation failed - use blocked() for error events
|
|
246
|
-
if (useCapabilityDispatch) {
|
|
247
|
-
// Capability dispatch: use behavior's blocked phase
|
|
248
|
-
events = (0, capability_dispatch_helper_1.executeCapabilityBlocked)(currentContext, actionValidation, command.actionId);
|
|
249
|
-
}
|
|
250
|
-
else if (action.blocked) {
|
|
251
|
-
events = action.blocked(currentContext, actionValidation);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
// Fallback for unmigrated actions
|
|
255
|
-
events = [{
|
|
256
|
-
id: `${turn}-error`,
|
|
257
|
-
type: 'action.error',
|
|
258
|
-
timestamp: Date.now(),
|
|
259
|
-
data: {
|
|
260
|
-
actionId: command.actionId,
|
|
261
|
-
messageId: actionValidation.error || 'validation_failed',
|
|
262
|
-
params: actionValidation.params || {}
|
|
263
|
-
},
|
|
264
|
-
entities: {}
|
|
265
|
-
}];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (config?.collectTiming) {
|
|
269
|
-
executionTime = Date.now() - executionStart;
|
|
270
|
-
}
|
|
271
|
-
// Process events and collect reactions (ADR-052 entity handlers)
|
|
272
|
-
let allEvents = events;
|
|
273
|
-
if (events.length > 0) {
|
|
274
|
-
const processed = this.eventProcessor.processEvents(events);
|
|
275
|
-
// Add reaction events from entity handlers
|
|
276
|
-
if (processed.reactions && processed.reactions.length > 0) {
|
|
277
|
-
allEvents = [...events, ...processed.reactions];
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
// Preserve all event properties (including requiresClientAction for platform events)
|
|
281
|
-
const sequenced = event_sequencer_1.eventSequencer.sequenceAll(allEvents, turn);
|
|
282
|
-
const result = {
|
|
283
|
-
turn,
|
|
284
|
-
input,
|
|
285
|
-
success: !events.some(e => e.type === 'action.error'),
|
|
286
|
-
events: sequenced,
|
|
287
|
-
actionId: command.actionId,
|
|
288
|
-
parsedCommand: command.parsed,
|
|
289
|
-
validatedCommand: command
|
|
290
|
-
};
|
|
291
|
-
// Add timing data if requested
|
|
292
|
-
if (config?.collectTiming) {
|
|
293
|
-
result.timing = {
|
|
294
|
-
parsing: parseTime,
|
|
295
|
-
execution: executionTime,
|
|
296
|
-
total: Date.now() - startTime
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
return result;
|
|
300
|
-
}
|
|
301
|
-
catch (error) {
|
|
302
|
-
// Minimal error handling - just return failure
|
|
303
|
-
const result = {
|
|
304
|
-
turn,
|
|
305
|
-
input,
|
|
306
|
-
success: false,
|
|
307
|
-
events: [event_sequencer_1.eventSequencer.sequence({
|
|
308
|
-
type: 'command.failed',
|
|
309
|
-
data: { reason: error.message, input }
|
|
310
|
-
}, turn)],
|
|
311
|
-
error: error.message
|
|
312
|
-
};
|
|
313
|
-
// Add timing data even for errors if requested
|
|
314
|
-
if (config?.collectTiming) {
|
|
315
|
-
result.timing = {
|
|
316
|
-
parsing: parseTime,
|
|
317
|
-
execution: executionTime,
|
|
318
|
-
total: Date.now() - startTime
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
exports.CommandExecutor = CommandExecutor;
|
|
326
|
-
function createCommandExecutor(world, actionRegistry, eventProcessor, parser, systemEvents) {
|
|
327
|
-
return new CommandExecutor(world, actionRegistry, eventProcessor, parser, systemEvents);
|
|
328
|
-
}
|
|
329
|
-
//# sourceMappingURL=command-executor.js.map
|