@sharpee/core 0.9.56-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/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/constants/attributes.d.ts +32 -0
- package/dist/constants/attributes.d.ts.map +1 -0
- package/dist/constants/attributes.js +53 -0
- package/dist/constants/attributes.js.map +1 -0
- package/dist/constants/core-events.d.ts +37 -0
- package/dist/constants/core-events.d.ts.map +1 -0
- package/dist/constants/core-events.js +50 -0
- package/dist/constants/core-events.js.map +1 -0
- package/dist/constants/entity-types.d.ts +15 -0
- package/dist/constants/entity-types.d.ts.map +1 -0
- package/dist/constants/entity-types.js +27 -0
- package/dist/constants/entity-types.js.map +1 -0
- package/dist/constants/index.d.ts +22 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +41 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/relationships.d.ts +25 -0
- package/dist/constants/relationships.d.ts.map +1 -0
- package/dist/constants/relationships.js +55 -0
- package/dist/constants/relationships.js.map +1 -0
- package/dist/debug/index.d.ts +5 -0
- package/dist/debug/index.d.ts.map +1 -0
- package/dist/debug/index.js +21 -0
- package/dist/debug/index.js.map +1 -0
- package/dist/debug/types.d.ts +65 -0
- package/dist/debug/types.d.ts.map +1 -0
- package/dist/debug/types.js +39 -0
- package/dist/debug/types.js.map +1 -0
- package/dist/events/event-factory.d.ts +81 -0
- package/dist/events/event-factory.d.ts.map +1 -0
- package/dist/events/event-factory.js +74 -0
- package/dist/events/event-factory.js.map +1 -0
- package/dist/events/event-helpers.d.ts +118 -0
- package/dist/events/event-helpers.d.ts.map +1 -0
- package/dist/events/event-helpers.js +151 -0
- package/dist/events/event-helpers.js.map +1 -0
- package/dist/events/event-registry.d.ts +154 -0
- package/dist/events/event-registry.d.ts.map +1 -0
- package/dist/events/event-registry.js +24 -0
- package/dist/events/event-registry.js.map +1 -0
- package/dist/events/event-source.d.ts +39 -0
- package/dist/events/event-source.d.ts.map +1 -0
- package/dist/events/event-source.js +57 -0
- package/dist/events/event-source.js.map +1 -0
- package/dist/events/event-system.d.ts +27 -0
- package/dist/events/event-system.d.ts.map +1 -0
- package/dist/events/event-system.js +64 -0
- package/dist/events/event-system.js.map +1 -0
- package/dist/events/game-events.d.ts +245 -0
- package/dist/events/game-events.d.ts.map +1 -0
- package/dist/events/game-events.js +250 -0
- package/dist/events/game-events.js.map +1 -0
- package/dist/events/index.d.ts +19 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +51 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/platform-events.d.ts +161 -0
- package/dist/events/platform-events.d.ts.map +1 -0
- package/dist/events/platform-events.js +135 -0
- package/dist/events/platform-events.js.map +1 -0
- package/dist/events/semantic-event-source.d.ts +85 -0
- package/dist/events/semantic-event-source.d.ts.map +1 -0
- package/dist/events/semantic-event-source.js +147 -0
- package/dist/events/semantic-event-source.js.map +1 -0
- package/dist/events/standard-events.d.ts +26 -0
- package/dist/events/standard-events.d.ts.map +1 -0
- package/dist/events/standard-events.js +27 -0
- package/dist/events/standard-events.js.map +1 -0
- package/dist/events/system-event.d.ts +62 -0
- package/dist/events/system-event.d.ts.map +1 -0
- package/dist/events/system-event.js +55 -0
- package/dist/events/system-event.js.map +1 -0
- package/dist/events/typed-event.d.ts +69 -0
- package/dist/events/typed-event.d.ts.map +1 -0
- package/dist/events/typed-event.js +20 -0
- package/dist/events/typed-event.js.map +1 -0
- package/dist/events/types.d.ts +105 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +4 -0
- package/dist/events/types.js.map +1 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +23 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/types.d.ts +117 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +4 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +20 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/registry.d.ts +61 -0
- package/dist/extensions/registry.d.ts.map +1 -0
- package/dist/extensions/registry.js +153 -0
- package/dist/extensions/registry.js.map +1 -0
- package/dist/extensions/types.d.ts +84 -0
- package/dist/extensions/types.d.ts.map +1 -0
- package/dist/extensions/types.js +15 -0
- package/dist/extensions/types.js.map +1 -0
- package/dist/ifid/ifid.d.ts +30 -0
- package/dist/ifid/ifid.d.ts.map +1 -0
- package/dist/ifid/ifid.js +52 -0
- package/dist/ifid/ifid.js.map +1 -0
- package/dist/ifid/index.d.ts +2 -0
- package/dist/ifid/index.d.ts.map +1 -0
- package/dist/ifid/index.js +9 -0
- package/dist/ifid/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/index.d.ts +2 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +3 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/story-metadata.d.ts +64 -0
- package/dist/metadata/story-metadata.d.ts.map +1 -0
- package/dist/metadata/story-metadata.js +5 -0
- package/dist/metadata/story-metadata.js.map +1 -0
- package/dist/query/index.d.ts +9 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +25 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/query-manager.d.ts +86 -0
- package/dist/query/query-manager.d.ts.map +1 -0
- package/dist/query/query-manager.js +391 -0
- package/dist/query/query-manager.js.map +1 -0
- package/dist/query/types.d.ts +188 -0
- package/dist/query/types.d.ts.map +1 -0
- package/dist/query/types.js +106 -0
- package/dist/query/types.js.map +1 -0
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/index.js +9 -0
- package/dist/random/index.js.map +1 -0
- package/dist/random/seeded-random.d.ts +32 -0
- package/dist/random/seeded-random.d.ts.map +1 -0
- package/dist/random/seeded-random.js +62 -0
- package/dist/random/seeded-random.js.map +1 -0
- package/dist/rules/compatibility.d.ts +46 -0
- package/dist/rules/compatibility.d.ts.map +1 -0
- package/dist/rules/compatibility.js +62 -0
- package/dist/rules/compatibility.js.map +1 -0
- package/dist/rules/condition-builder.d.ts +23 -0
- package/dist/rules/condition-builder.d.ts.map +1 -0
- package/dist/rules/condition-builder.js +16 -0
- package/dist/rules/condition-builder.js.map +1 -0
- package/dist/rules/helpers.d.ts +51 -0
- package/dist/rules/helpers.d.ts.map +1 -0
- package/dist/rules/helpers.js +111 -0
- package/dist/rules/helpers.js.map +1 -0
- package/dist/rules/index.d.ts +12 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +34 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/rule-system.d.ts +6 -0
- package/dist/rules/rule-system.d.ts.map +1 -0
- package/dist/rules/rule-system.js +10 -0
- package/dist/rules/rule-system.js.map +1 -0
- package/dist/rules/rule-world-adapter.d.ts +43 -0
- package/dist/rules/rule-world-adapter.d.ts.map +1 -0
- package/dist/rules/rule-world-adapter.js +74 -0
- package/dist/rules/rule-world-adapter.js.map +1 -0
- package/dist/rules/simple-rule-system.d.ts +36 -0
- package/dist/rules/simple-rule-system.d.ts.map +1 -0
- package/dist/rules/simple-rule-system.js +135 -0
- package/dist/rules/simple-rule-system.js.map +1 -0
- package/dist/rules/types.d.ts +64 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +6 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/types/attribute.d.ts +40 -0
- package/dist/types/attribute.d.ts.map +1 -0
- package/dist/types/attribute.js +4 -0
- package/dist/types/attribute.js.map +1 -0
- package/dist/types/entity.d.ts +47 -0
- package/dist/types/entity.d.ts.map +1 -0
- package/dist/types/entity.js +4 -0
- package/dist/types/entity.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +27 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/relationship.d.ts +44 -0
- package/dist/types/relationship.d.ts.map +1 -0
- package/dist/types/relationship.js +4 -0
- package/dist/types/relationship.js.map +1 -0
- package/dist/types/result.d.ts +81 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +79 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/save-data.d.ts +264 -0
- package/dist/types/save-data.d.ts.map +1 -0
- package/dist/types/save-data.js +6 -0
- package/dist/types/save-data.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Manager - Manages pending queries and routes responses
|
|
3
|
+
*
|
|
4
|
+
* This is the core component of the PC communication system (ADR-018).
|
|
5
|
+
* It tracks pending queries, validates responses, and routes them to
|
|
6
|
+
* appropriate handlers.
|
|
7
|
+
*/
|
|
8
|
+
import EventEmitter from 'eventemitter3';
|
|
9
|
+
import { IPendingQuery, IQueryResponse, IQueryState, IQueryHandler, QueryValidator, IQueryEvents } from './types';
|
|
10
|
+
import { ISemanticEventSource } from '../events';
|
|
11
|
+
/**
|
|
12
|
+
* Query Manager implementation
|
|
13
|
+
*/
|
|
14
|
+
export declare class QueryManager extends EventEmitter {
|
|
15
|
+
private state;
|
|
16
|
+
private handlers;
|
|
17
|
+
private validators;
|
|
18
|
+
private timeouts;
|
|
19
|
+
private eventSource;
|
|
20
|
+
constructor();
|
|
21
|
+
/**
|
|
22
|
+
* Register a query handler
|
|
23
|
+
*/
|
|
24
|
+
registerHandler(id: string, handler: IQueryHandler): void;
|
|
25
|
+
/**
|
|
26
|
+
* Register a response validator
|
|
27
|
+
*/
|
|
28
|
+
registerValidator(name: string, validator: QueryValidator): void;
|
|
29
|
+
/**
|
|
30
|
+
* Present a query to the player
|
|
31
|
+
*/
|
|
32
|
+
askQuery(query: IPendingQuery): Promise<IQueryResponse | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Process input while a query is pending
|
|
35
|
+
*/
|
|
36
|
+
processInput(input: string): 'handled' | 'interrupt' | 'pass';
|
|
37
|
+
/**
|
|
38
|
+
* Cancel the current query
|
|
39
|
+
*/
|
|
40
|
+
cancelCurrentQuery(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get current state
|
|
43
|
+
*/
|
|
44
|
+
getState(): Readonly<IQueryState>;
|
|
45
|
+
/**
|
|
46
|
+
* Get event source for connecting to engine
|
|
47
|
+
*/
|
|
48
|
+
getEventSource(): ISemanticEventSource;
|
|
49
|
+
/**
|
|
50
|
+
* Check if there's a pending query
|
|
51
|
+
*/
|
|
52
|
+
hasPendingQuery(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get the current pending query
|
|
55
|
+
*/
|
|
56
|
+
getCurrentQuery(): IPendingQuery | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Clear all queries
|
|
59
|
+
*/
|
|
60
|
+
clearAll(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Handle query timeout
|
|
63
|
+
*/
|
|
64
|
+
private handleTimeout;
|
|
65
|
+
/**
|
|
66
|
+
* Interrupt a query with a command
|
|
67
|
+
*/
|
|
68
|
+
private interruptQuery;
|
|
69
|
+
/**
|
|
70
|
+
* Find handler for a query
|
|
71
|
+
*/
|
|
72
|
+
private findHandler;
|
|
73
|
+
/**
|
|
74
|
+
* Check if input looks like a command
|
|
75
|
+
*/
|
|
76
|
+
private looksLikeCommand;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a new query manager instance
|
|
80
|
+
*/
|
|
81
|
+
export declare function createQueryManager(): QueryManager;
|
|
82
|
+
/**
|
|
83
|
+
* Type guard for query events
|
|
84
|
+
*/
|
|
85
|
+
export declare function isQueryEvent<K extends keyof IQueryEvents>(event: string | symbol, key: K): event is K;
|
|
86
|
+
//# sourceMappingURL=query-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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O,CAAC,gBAAgB;CAWzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,YAAY,EACvD,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,GAAG,EAAE,CAAC,GACL,KAAK,IAAI,CAAC,CAEZ"}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query Manager - Manages pending queries and routes responses
|
|
4
|
+
*
|
|
5
|
+
* This is the core component of the PC communication system (ADR-018).
|
|
6
|
+
* It tracks pending queries, validates responses, and routes them to
|
|
7
|
+
* appropriate handlers.
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.QueryManager = void 0;
|
|
14
|
+
exports.createQueryManager = createQueryManager;
|
|
15
|
+
exports.isQueryEvent = isQueryEvent;
|
|
16
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
17
|
+
const types_1 = require("./types");
|
|
18
|
+
const events_1 = require("../events");
|
|
19
|
+
/**
|
|
20
|
+
* Query Manager implementation
|
|
21
|
+
*/
|
|
22
|
+
class QueryManager extends eventemitter3_1.default {
|
|
23
|
+
state = {
|
|
24
|
+
queryStack: [],
|
|
25
|
+
history: [],
|
|
26
|
+
interceptingInput: false
|
|
27
|
+
};
|
|
28
|
+
handlers = new Map();
|
|
29
|
+
validators = new Map();
|
|
30
|
+
timeouts = new Map();
|
|
31
|
+
eventSource = (0, events_1.createSemanticEventSource)();
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
// Register standard validators
|
|
35
|
+
this.registerValidator('yes_no', types_1.StandardValidators.yesNo);
|
|
36
|
+
this.registerValidator('numeric', (response, query) => {
|
|
37
|
+
const min = query.context.min;
|
|
38
|
+
const max = query.context.max;
|
|
39
|
+
return types_1.StandardValidators.numeric(response, min, max);
|
|
40
|
+
});
|
|
41
|
+
this.registerValidator('multiple_choice', (response, query) => {
|
|
42
|
+
return types_1.StandardValidators.multipleChoice(response, query.options || []);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register a query handler
|
|
47
|
+
*/
|
|
48
|
+
registerHandler(id, handler) {
|
|
49
|
+
this.handlers.set(id, handler);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Register a response validator
|
|
53
|
+
*/
|
|
54
|
+
registerValidator(name, validator) {
|
|
55
|
+
this.validators.set(name, validator);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Present a query to the player
|
|
59
|
+
*/
|
|
60
|
+
async askQuery(query) {
|
|
61
|
+
// If there's already a pending query, stack this one
|
|
62
|
+
if (this.state.pendingQuery) {
|
|
63
|
+
if (query.priority && query.priority > (this.state.pendingQuery.priority || 0)) {
|
|
64
|
+
// Higher priority interrupts
|
|
65
|
+
this.state.queryStack.unshift(this.state.pendingQuery);
|
|
66
|
+
this.state.pendingQuery = query;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Queue for later
|
|
70
|
+
this.state.queryStack.push(query);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.state.pendingQuery = query;
|
|
76
|
+
}
|
|
77
|
+
// Start intercepting input
|
|
78
|
+
this.state.interceptingInput = true;
|
|
79
|
+
// Emit the query event
|
|
80
|
+
this.emit('query:pending', query);
|
|
81
|
+
// Set timeout if specified
|
|
82
|
+
if (query.timeout) {
|
|
83
|
+
const timeoutId = setTimeout(() => {
|
|
84
|
+
this.handleTimeout(query);
|
|
85
|
+
}, query.timeout);
|
|
86
|
+
this.timeouts.set(query.id, timeoutId);
|
|
87
|
+
}
|
|
88
|
+
// Return a promise that resolves when answered
|
|
89
|
+
return new Promise((resolve) => {
|
|
90
|
+
const answerHandler = (response, answeredQuery) => {
|
|
91
|
+
if (answeredQuery.id === query.id) {
|
|
92
|
+
this.off('query:answered', answerHandler);
|
|
93
|
+
this.off('query:timeout', timeoutHandler);
|
|
94
|
+
this.off('query:cancelled', cancelHandler);
|
|
95
|
+
resolve(response);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const timeoutHandler = (timedOutQuery) => {
|
|
99
|
+
if (timedOutQuery.id === query.id) {
|
|
100
|
+
this.off('query:answered', answerHandler);
|
|
101
|
+
this.off('query:timeout', timeoutHandler);
|
|
102
|
+
this.off('query:cancelled', cancelHandler);
|
|
103
|
+
resolve(null);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const cancelHandler = (cancelledQuery) => {
|
|
107
|
+
if (cancelledQuery.id === query.id) {
|
|
108
|
+
this.off('query:answered', answerHandler);
|
|
109
|
+
this.off('query:timeout', timeoutHandler);
|
|
110
|
+
this.off('query:cancelled', cancelHandler);
|
|
111
|
+
resolve(null);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
this.on('query:answered', answerHandler);
|
|
115
|
+
this.on('query:timeout', timeoutHandler);
|
|
116
|
+
this.on('query:cancelled', cancelHandler);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Process input while a query is pending
|
|
121
|
+
*/
|
|
122
|
+
processInput(input) {
|
|
123
|
+
if (!this.state.pendingQuery || !this.state.interceptingInput) {
|
|
124
|
+
return 'pass';
|
|
125
|
+
}
|
|
126
|
+
const query = this.state.pendingQuery;
|
|
127
|
+
// Check if this looks like a command (for interruption)
|
|
128
|
+
if (this.looksLikeCommand(input) && query.allowInterruption) {
|
|
129
|
+
this.interruptQuery(query, input);
|
|
130
|
+
return 'interrupt';
|
|
131
|
+
}
|
|
132
|
+
// Validate the response
|
|
133
|
+
let validationResult = { valid: true, normalized: input };
|
|
134
|
+
if (query.validator) {
|
|
135
|
+
const validator = this.validators.get(query.validator);
|
|
136
|
+
if (validator) {
|
|
137
|
+
validationResult = validator(input, query);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (query.type === 'multiple_choice' && query.options) {
|
|
141
|
+
// Default validation for multiple choice queries
|
|
142
|
+
const trimmed = input.trim().toLowerCase();
|
|
143
|
+
const optionIndex = parseInt(trimmed, 10) - 1;
|
|
144
|
+
if (!isNaN(optionIndex) && optionIndex >= 0 && optionIndex < query.options.length) {
|
|
145
|
+
// Numeric selection
|
|
146
|
+
validationResult = { valid: true, normalized: optionIndex };
|
|
147
|
+
}
|
|
148
|
+
else if (query.options.some(opt => opt.toLowerCase() === trimmed)) {
|
|
149
|
+
// Text match
|
|
150
|
+
validationResult = { valid: true, normalized: trimmed };
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Invalid response
|
|
154
|
+
validationResult = {
|
|
155
|
+
valid: false,
|
|
156
|
+
message: `Please select one of the available options: ${query.options.join(', ')}`,
|
|
157
|
+
hint: 'You can enter the option number or text'
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (!validationResult.valid) {
|
|
162
|
+
this.emit('query:invalid', input, validationResult, query);
|
|
163
|
+
// Also emit as a semantic event
|
|
164
|
+
const invalidEventData = {
|
|
165
|
+
queryId: query.id,
|
|
166
|
+
input,
|
|
167
|
+
message: validationResult.message || 'Invalid response',
|
|
168
|
+
hint: validationResult.hint
|
|
169
|
+
};
|
|
170
|
+
const invalidEvent = {
|
|
171
|
+
id: `evt_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
172
|
+
type: 'query.invalid',
|
|
173
|
+
timestamp: Date.now(),
|
|
174
|
+
entities: {},
|
|
175
|
+
data: invalidEventData
|
|
176
|
+
};
|
|
177
|
+
this.eventSource.emit(invalidEvent);
|
|
178
|
+
return 'handled';
|
|
179
|
+
}
|
|
180
|
+
// Create response object
|
|
181
|
+
const response = {
|
|
182
|
+
queryId: query.id,
|
|
183
|
+
rawInput: input,
|
|
184
|
+
response: validationResult.normalized || input,
|
|
185
|
+
selectedIndex: typeof validationResult.normalized === 'number' ?
|
|
186
|
+
validationResult.normalized : undefined,
|
|
187
|
+
wasInterrupted: false,
|
|
188
|
+
timestamp: Date.now()
|
|
189
|
+
};
|
|
190
|
+
// Clear timeout
|
|
191
|
+
const timeoutId = this.timeouts.get(query.id);
|
|
192
|
+
if (timeoutId) {
|
|
193
|
+
clearTimeout(timeoutId);
|
|
194
|
+
this.timeouts.delete(query.id);
|
|
195
|
+
}
|
|
196
|
+
// Record in history
|
|
197
|
+
this.state.history.push({
|
|
198
|
+
query,
|
|
199
|
+
response,
|
|
200
|
+
result: 'answered'
|
|
201
|
+
});
|
|
202
|
+
// Clear current query
|
|
203
|
+
this.state.pendingQuery = undefined;
|
|
204
|
+
// Process next query in stack
|
|
205
|
+
if (this.state.queryStack.length > 0) {
|
|
206
|
+
const nextQuery = this.state.queryStack.shift();
|
|
207
|
+
this.state.pendingQuery = nextQuery;
|
|
208
|
+
this.emit('query:pending', nextQuery);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
this.state.interceptingInput = false;
|
|
212
|
+
}
|
|
213
|
+
// Emit answer event
|
|
214
|
+
this.emit('query:answered', response, query);
|
|
215
|
+
// Route to handler if registered
|
|
216
|
+
const handler = this.findHandler(query);
|
|
217
|
+
if (handler) {
|
|
218
|
+
handler.handleResponse(response, query);
|
|
219
|
+
}
|
|
220
|
+
return 'handled';
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Cancel the current query
|
|
224
|
+
*/
|
|
225
|
+
cancelCurrentQuery() {
|
|
226
|
+
if (!this.state.pendingQuery)
|
|
227
|
+
return;
|
|
228
|
+
const query = this.state.pendingQuery;
|
|
229
|
+
// Clear timeout
|
|
230
|
+
const timeoutId = this.timeouts.get(query.id);
|
|
231
|
+
if (timeoutId) {
|
|
232
|
+
clearTimeout(timeoutId);
|
|
233
|
+
this.timeouts.delete(query.id);
|
|
234
|
+
}
|
|
235
|
+
// Record in history
|
|
236
|
+
this.state.history.push({
|
|
237
|
+
query,
|
|
238
|
+
result: 'cancelled'
|
|
239
|
+
});
|
|
240
|
+
// Clear current query
|
|
241
|
+
this.state.pendingQuery = undefined;
|
|
242
|
+
// Process next query
|
|
243
|
+
if (this.state.queryStack.length > 0) {
|
|
244
|
+
const nextQuery = this.state.queryStack.shift();
|
|
245
|
+
this.state.pendingQuery = nextQuery;
|
|
246
|
+
this.emit('query:pending', nextQuery);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
this.state.interceptingInput = false;
|
|
250
|
+
}
|
|
251
|
+
// Emit cancel event
|
|
252
|
+
this.emit('query:cancelled', query);
|
|
253
|
+
// Notify handler
|
|
254
|
+
const handler = this.findHandler(query);
|
|
255
|
+
if (handler && handler.handleCancel) {
|
|
256
|
+
handler.handleCancel(query);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get current state
|
|
261
|
+
*/
|
|
262
|
+
getState() {
|
|
263
|
+
return { ...this.state };
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get event source for connecting to engine
|
|
267
|
+
*/
|
|
268
|
+
getEventSource() {
|
|
269
|
+
return this.eventSource;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Check if there's a pending query
|
|
273
|
+
*/
|
|
274
|
+
hasPendingQuery() {
|
|
275
|
+
return !!this.state.pendingQuery;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get the current pending query
|
|
279
|
+
*/
|
|
280
|
+
getCurrentQuery() {
|
|
281
|
+
return this.state.pendingQuery;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Clear all queries
|
|
285
|
+
*/
|
|
286
|
+
clearAll() {
|
|
287
|
+
// Cancel current query
|
|
288
|
+
if (this.state.pendingQuery) {
|
|
289
|
+
this.cancelCurrentQuery();
|
|
290
|
+
}
|
|
291
|
+
// Clear stack
|
|
292
|
+
this.state.queryStack = [];
|
|
293
|
+
this.state.interceptingInput = false;
|
|
294
|
+
// Clear all timeouts
|
|
295
|
+
for (const [, timeoutId] of this.timeouts) {
|
|
296
|
+
clearTimeout(timeoutId);
|
|
297
|
+
}
|
|
298
|
+
this.timeouts.clear();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Handle query timeout
|
|
302
|
+
*/
|
|
303
|
+
handleTimeout(query) {
|
|
304
|
+
if (this.state.pendingQuery?.id !== query.id)
|
|
305
|
+
return;
|
|
306
|
+
// Record in history
|
|
307
|
+
this.state.history.push({
|
|
308
|
+
query,
|
|
309
|
+
result: 'timeout'
|
|
310
|
+
});
|
|
311
|
+
// Clear current query
|
|
312
|
+
this.state.pendingQuery = undefined;
|
|
313
|
+
this.timeouts.delete(query.id);
|
|
314
|
+
// Process next query
|
|
315
|
+
if (this.state.queryStack.length > 0) {
|
|
316
|
+
const nextQuery = this.state.queryStack.shift();
|
|
317
|
+
this.state.pendingQuery = nextQuery;
|
|
318
|
+
this.emit('query:pending', nextQuery);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
this.state.interceptingInput = false;
|
|
322
|
+
}
|
|
323
|
+
// Emit timeout event
|
|
324
|
+
this.emit('query:timeout', query);
|
|
325
|
+
// Notify handler
|
|
326
|
+
const handler = this.findHandler(query);
|
|
327
|
+
if (handler && handler.handleTimeout) {
|
|
328
|
+
handler.handleTimeout(query);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Interrupt a query with a command
|
|
333
|
+
*/
|
|
334
|
+
interruptQuery(query, command) {
|
|
335
|
+
// Clear timeout
|
|
336
|
+
const timeoutId = this.timeouts.get(query.id);
|
|
337
|
+
if (timeoutId) {
|
|
338
|
+
clearTimeout(timeoutId);
|
|
339
|
+
this.timeouts.delete(query.id);
|
|
340
|
+
}
|
|
341
|
+
// Record in history
|
|
342
|
+
this.state.history.push({
|
|
343
|
+
query,
|
|
344
|
+
result: 'cancelled'
|
|
345
|
+
});
|
|
346
|
+
// Clear current query
|
|
347
|
+
this.state.pendingQuery = undefined;
|
|
348
|
+
// Don't process next query - let the command execute
|
|
349
|
+
this.state.interceptingInput = false;
|
|
350
|
+
// Emit interrupt event
|
|
351
|
+
this.emit('query:interrupted', query, command);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Find handler for a query
|
|
355
|
+
*/
|
|
356
|
+
findHandler(query) {
|
|
357
|
+
for (const [, handler] of this.handlers) {
|
|
358
|
+
if (handler.canHandle(query)) {
|
|
359
|
+
return handler;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Check if input looks like a command
|
|
366
|
+
*/
|
|
367
|
+
looksLikeCommand(input) {
|
|
368
|
+
const commandPatterns = [
|
|
369
|
+
/^(look|take|drop|go|examine|inventory|save|load|help)/i,
|
|
370
|
+
/^(n|s|e|w|ne|nw|se|sw|up|down|in|out)$/i,
|
|
371
|
+
/^x\s+/i, // "x thing" for examine
|
|
372
|
+
/^g\s+/i, // "g place" for go
|
|
373
|
+
/^l$/i // "l" for look
|
|
374
|
+
];
|
|
375
|
+
return commandPatterns.some(pattern => pattern.test(input.trim()));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
exports.QueryManager = QueryManager;
|
|
379
|
+
/**
|
|
380
|
+
* Create a new query manager instance
|
|
381
|
+
*/
|
|
382
|
+
function createQueryManager() {
|
|
383
|
+
return new QueryManager();
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Type guard for query events
|
|
387
|
+
*/
|
|
388
|
+
function isQueryEvent(event, key) {
|
|
389
|
+
return event === key;
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=query-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-manager.js","sour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H,SAAgB,kBAAkB;IAChC,OAAO,IAAI,YAAY,EAAE,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAC1B,KAAsB,EACtB,GAAM;IAEN,OAAO,KAAK,KAAK,GAAG,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the PC communication query system
|
|
3
|
+
*
|
|
4
|
+
* These types define the structure of queries, responses, and validation
|
|
5
|
+
* for the client query system (ADR-018).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Sources that can initiate queries
|
|
9
|
+
*/
|
|
10
|
+
export declare enum QuerySource {
|
|
11
|
+
/** System-level queries (save, quit, restart) */
|
|
12
|
+
SYSTEM = "system",
|
|
13
|
+
/** Parser disambiguation queries */
|
|
14
|
+
DISAMBIGUATION = "disambiguation",
|
|
15
|
+
/** NPC dialogue queries */
|
|
16
|
+
NPC = "npc",
|
|
17
|
+
/** Game mechanic queries (passwords, combinations) */
|
|
18
|
+
GAME_MECHANIC = "mechanic",
|
|
19
|
+
/** Narrative-driven queries */
|
|
20
|
+
NARRATIVE = "narrative"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Types of queries that can be presented
|
|
24
|
+
*/
|
|
25
|
+
export declare enum QueryType {
|
|
26
|
+
/** Simple yes/no question */
|
|
27
|
+
YES_NO = "yes_no",
|
|
28
|
+
/** Multiple choice with predefined options */
|
|
29
|
+
MULTIPLE_CHOICE = "multiple_choice",
|
|
30
|
+
/** Open-ended text input */
|
|
31
|
+
FREE_TEXT = "free_text",
|
|
32
|
+
/** Numeric input only */
|
|
33
|
+
NUMERIC = "numeric",
|
|
34
|
+
/** Special type for disambiguation */
|
|
35
|
+
DISAMBIGUATION = "disambiguation"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A query waiting for player response
|
|
39
|
+
*/
|
|
40
|
+
export interface IPendingQuery {
|
|
41
|
+
/** Unique identifier for this query */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Source that initiated the query */
|
|
44
|
+
source: QuerySource;
|
|
45
|
+
/** Type of query */
|
|
46
|
+
type: QueryType;
|
|
47
|
+
/** Message ID for the query prompt */
|
|
48
|
+
messageId: string;
|
|
49
|
+
/** Parameters for message formatting */
|
|
50
|
+
messageParams?: Record<string, any>;
|
|
51
|
+
/** Available options (for multiple choice) */
|
|
52
|
+
options?: string[];
|
|
53
|
+
/** Additional context for the query handler */
|
|
54
|
+
context: IQueryContext;
|
|
55
|
+
/** Whether the player can interrupt this query */
|
|
56
|
+
allowInterruption: boolean;
|
|
57
|
+
/** Name of the validator to use */
|
|
58
|
+
validator?: string;
|
|
59
|
+
/** Optional timeout in milliseconds */
|
|
60
|
+
timeout?: number;
|
|
61
|
+
/** Timestamp when query was created */
|
|
62
|
+
created: number;
|
|
63
|
+
/** Priority level (higher = more important) */
|
|
64
|
+
priority?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Context data passed with queries
|
|
68
|
+
*/
|
|
69
|
+
export interface IQueryContext {
|
|
70
|
+
/** Query-specific data */
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
/** For quit queries */
|
|
73
|
+
score?: number;
|
|
74
|
+
maxScore?: number;
|
|
75
|
+
moves?: number;
|
|
76
|
+
hasUnsavedProgress?: boolean;
|
|
77
|
+
nearComplete?: boolean;
|
|
78
|
+
/** For save queries */
|
|
79
|
+
existingFile?: string;
|
|
80
|
+
lastSaveTime?: number;
|
|
81
|
+
/** For disambiguation */
|
|
82
|
+
candidates?: Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
}>;
|
|
87
|
+
/** For NPC queries */
|
|
88
|
+
npcId?: string;
|
|
89
|
+
npcName?: string;
|
|
90
|
+
topic?: string;
|
|
91
|
+
/** For game mechanic queries */
|
|
92
|
+
attempts?: number;
|
|
93
|
+
maxAttempts?: number;
|
|
94
|
+
hint?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Player's response to a query
|
|
98
|
+
*/
|
|
99
|
+
export interface IQueryResponse {
|
|
100
|
+
/** ID of the query being responded to */
|
|
101
|
+
queryId: string;
|
|
102
|
+
/** Raw input from the player */
|
|
103
|
+
rawInput: string;
|
|
104
|
+
/** Processed/normalized response */
|
|
105
|
+
response: string | number | boolean;
|
|
106
|
+
/** Selected option index (for multiple choice) */
|
|
107
|
+
selectedIndex?: number;
|
|
108
|
+
/** Whether this was an interruption */
|
|
109
|
+
wasInterrupted: boolean;
|
|
110
|
+
/** Timestamp of response */
|
|
111
|
+
timestamp: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Function to validate a response
|
|
115
|
+
*/
|
|
116
|
+
export type QueryValidator = (response: string, query: IPendingQuery) => IValidationResult;
|
|
117
|
+
/**
|
|
118
|
+
* Result of validating a response
|
|
119
|
+
*/
|
|
120
|
+
export interface IValidationResult {
|
|
121
|
+
/** Whether the response is valid */
|
|
122
|
+
valid: boolean;
|
|
123
|
+
/** Error message if invalid */
|
|
124
|
+
message?: string;
|
|
125
|
+
/** Normalized/parsed response value */
|
|
126
|
+
normalized?: any;
|
|
127
|
+
/** Hint for the player */
|
|
128
|
+
hint?: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Handler for processing query responses
|
|
132
|
+
*/
|
|
133
|
+
export interface IQueryHandler {
|
|
134
|
+
/** Query types this handler can process */
|
|
135
|
+
canHandle: (query: IPendingQuery) => boolean;
|
|
136
|
+
/** Process a validated response */
|
|
137
|
+
handleResponse: (response: IQueryResponse, query: IPendingQuery) => void;
|
|
138
|
+
/** Handle query timeout */
|
|
139
|
+
handleTimeout?: (query: IPendingQuery) => void;
|
|
140
|
+
/** Handle query cancellation */
|
|
141
|
+
handleCancel?: (query: IPendingQuery) => void;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Query manager state
|
|
145
|
+
*/
|
|
146
|
+
export interface IQueryState {
|
|
147
|
+
/** Currently active query */
|
|
148
|
+
pendingQuery?: IPendingQuery;
|
|
149
|
+
/** Stack of queries waiting to be presented */
|
|
150
|
+
queryStack: IPendingQuery[];
|
|
151
|
+
/** History of recent queries and responses */
|
|
152
|
+
history: Array<{
|
|
153
|
+
query: IPendingQuery;
|
|
154
|
+
response?: IQueryResponse;
|
|
155
|
+
result: 'answered' | 'timeout' | 'cancelled';
|
|
156
|
+
}>;
|
|
157
|
+
/** Whether input is currently being routed to query system */
|
|
158
|
+
interceptingInput: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Events emitted by the query system
|
|
162
|
+
*/
|
|
163
|
+
export interface IQueryEvents {
|
|
164
|
+
/** A new query needs to be presented to the player */
|
|
165
|
+
'query:pending': (query: IPendingQuery) => void;
|
|
166
|
+
/** A query was answered */
|
|
167
|
+
'query:answered': (response: IQueryResponse, query: IPendingQuery) => void;
|
|
168
|
+
/** A query timed out */
|
|
169
|
+
'query:timeout': (query: IPendingQuery) => void;
|
|
170
|
+
/** A query was cancelled */
|
|
171
|
+
'query:cancelled': (query: IPendingQuery) => void;
|
|
172
|
+
/** A query was interrupted by a command */
|
|
173
|
+
'query:interrupted': (query: IPendingQuery, command: string) => void;
|
|
174
|
+
/** Validation failed for a response */
|
|
175
|
+
'query:invalid': (response: string, result: IValidationResult, query: IPendingQuery) => void;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Standard validators
|
|
179
|
+
*/
|
|
180
|
+
export declare const StandardValidators: {
|
|
181
|
+
/** Validate yes/no responses */
|
|
182
|
+
yesNo: (response: string) => IValidationResult;
|
|
183
|
+
/** Validate numeric responses */
|
|
184
|
+
numeric: (response: string, min?: number, max?: number) => IValidationResult;
|
|
185
|
+
/** Validate multiple choice responses */
|
|
186
|
+
multipleChoice: (response: string, options: string[]) => IValidationResult;
|
|
187
|
+
};
|
|
188
|
+
//# sourceMappingURL=types.d.ts.map
|