@sharpee/character 0.9.106
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/apply.d.ts +25 -0
- package/apply.d.ts.map +1 -0
- package/apply.js +36 -0
- package/apply.js.map +1 -0
- package/character-builder.d.ts +282 -0
- package/character-builder.d.ts.map +1 -0
- package/character-builder.js +475 -0
- package/character-builder.js.map +1 -0
- package/cognitive-presets.d.ts +29 -0
- package/cognitive-presets.d.ts.map +1 -0
- package/cognitive-presets.js +89 -0
- package/cognitive-presets.js.map +1 -0
- package/index.d.ts +16 -0
- package/index.d.ts.map +1 -0
- package/index.js +25 -0
- package/index.js.map +1 -0
- package/package.json +40 -0
- package/vocabulary-extension.d.ts +79 -0
- package/vocabulary-extension.d.ts.map +1 -0
- package/vocabulary-extension.js +87 -0
- package/vocabulary-extension.js.map +1 -0
package/apply.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply compiled character data to an entity (ADR-141)
|
|
3
|
+
*
|
|
4
|
+
* Convenience function that creates a CharacterModelTrait from compiled
|
|
5
|
+
* builder output, registers custom predicates, and adds the trait to
|
|
6
|
+
* the entity.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: applyCharacter.
|
|
9
|
+
* Owner context: @sharpee/character
|
|
10
|
+
*/
|
|
11
|
+
import { IFEntity, CharacterModelTrait } from "../world-model/index";
|
|
12
|
+
import { CompiledCharacter } from './character-builder';
|
|
13
|
+
/**
|
|
14
|
+
* Apply a compiled character to an entity.
|
|
15
|
+
*
|
|
16
|
+
* Creates the CharacterModelTrait, registers custom predicates,
|
|
17
|
+
* and adds the trait to the entity. Returns the trait for further
|
|
18
|
+
* programmatic manipulation if needed.
|
|
19
|
+
*
|
|
20
|
+
* @param entity - The NPC entity to apply the character model to
|
|
21
|
+
* @param compiled - Output of CharacterBuilder.compile()
|
|
22
|
+
* @returns The created CharacterModelTrait instance
|
|
23
|
+
*/
|
|
24
|
+
export declare function applyCharacter(entity: IFEntity, compiled: CompiledCharacter): CharacterModelTrait;
|
|
25
|
+
//# sourceMappingURL=apply.d.ts.map
|
package/apply.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/character/src/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,QAAQ,EACR,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,iBAAiB,GAC1B,mBAAmB,CAYrB"}
|
package/apply.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Apply compiled character data to an entity (ADR-141)
|
|
4
|
+
*
|
|
5
|
+
* Convenience function that creates a CharacterModelTrait from compiled
|
|
6
|
+
* builder output, registers custom predicates, and adds the trait to
|
|
7
|
+
* the entity.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: applyCharacter.
|
|
10
|
+
* Owner context: @sharpee/character
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.applyCharacter = applyCharacter;
|
|
14
|
+
const world_model_1 = require("../world-model/index.js");
|
|
15
|
+
/**
|
|
16
|
+
* Apply a compiled character to an entity.
|
|
17
|
+
*
|
|
18
|
+
* Creates the CharacterModelTrait, registers custom predicates,
|
|
19
|
+
* and adds the trait to the entity. Returns the trait for further
|
|
20
|
+
* programmatic manipulation if needed.
|
|
21
|
+
*
|
|
22
|
+
* @param entity - The NPC entity to apply the character model to
|
|
23
|
+
* @param compiled - Output of CharacterBuilder.compile()
|
|
24
|
+
* @returns The created CharacterModelTrait instance
|
|
25
|
+
*/
|
|
26
|
+
function applyCharacter(entity, compiled) {
|
|
27
|
+
const trait = new world_model_1.CharacterModelTrait(compiled.traitData);
|
|
28
|
+
// Register custom predicates
|
|
29
|
+
for (const [name, fn] of compiled.customPredicates) {
|
|
30
|
+
trait.registerPredicate(name, fn);
|
|
31
|
+
}
|
|
32
|
+
// Add trait to entity
|
|
33
|
+
entity.add(trait);
|
|
34
|
+
return trait;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=apply.js.map
|
package/apply.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/apply.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAmBH,wCAeC;AAhCD,sDAG8B;AAG9B;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAC5B,MAAgB,EAChB,QAA2B;IAE3B,MAAM,KAAK,GAAG,IAAI,iCAAmB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAE1D,6BAA6B;IAC7B,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,gBAAgB,EAAE,CAAC;QACnD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,sBAAsB;IACtB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAElB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent character builder (ADR-141)
|
|
3
|
+
*
|
|
4
|
+
* Authors describe characters in words; the builder accumulates state
|
|
5
|
+
* and compiles it into CharacterModelTrait data, event handlers, and
|
|
6
|
+
* state mutation rules.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: CharacterBuilder, TriggerBuilder.
|
|
9
|
+
* Owner context: @sharpee/character
|
|
10
|
+
*/
|
|
11
|
+
import { PersonalityExpr, DispositionWord, Mood, ThreatLevel, CognitiveProfile, ConfidenceWord, LucidityConfig, PerceptionFilterConfig, PerceivedEvent, CharacterPredicate, ICharacterModelData } from "../world-model/index";
|
|
12
|
+
import { CognitivePresetName } from './cognitive-presets';
|
|
13
|
+
import { VocabularyExtension } from './vocabulary-extension';
|
|
14
|
+
/** A compiled state mutation triggered by an event or condition. */
|
|
15
|
+
export interface CompiledTrigger {
|
|
16
|
+
triggerName: string;
|
|
17
|
+
condition?: string;
|
|
18
|
+
mutations: TriggerMutation[];
|
|
19
|
+
}
|
|
20
|
+
/** A single mutation within a trigger. */
|
|
21
|
+
export type TriggerMutation = {
|
|
22
|
+
type: 'setMood';
|
|
23
|
+
mood: Mood | string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'setDisposition';
|
|
26
|
+
entityId: string;
|
|
27
|
+
word: DispositionWord;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'setThreat';
|
|
30
|
+
level: ThreatLevel;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'adjustThreat';
|
|
33
|
+
delta: number;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'becomesLucid';
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Fluent chain for defining state transitions on triggers.
|
|
39
|
+
*
|
|
40
|
+
* Usage: `builder.on('player threatens').becomes('panicked').feelsAbout('player', 'wary of')`
|
|
41
|
+
*/
|
|
42
|
+
export declare class TriggerBuilder {
|
|
43
|
+
private trigger;
|
|
44
|
+
private parentBuilder;
|
|
45
|
+
constructor(triggerName: string, parent: CharacterBuilder);
|
|
46
|
+
/**
|
|
47
|
+
* Add a condition predicate to this trigger.
|
|
48
|
+
*
|
|
49
|
+
* @param predicate - Predicate name that must be true for this trigger to fire
|
|
50
|
+
* @returns this for chaining
|
|
51
|
+
*/
|
|
52
|
+
if(predicate: string): TriggerBuilder;
|
|
53
|
+
/**
|
|
54
|
+
* Set the NPC's mood when this trigger fires.
|
|
55
|
+
*
|
|
56
|
+
* @param mood - Mood word
|
|
57
|
+
* @returns this for chaining
|
|
58
|
+
*/
|
|
59
|
+
becomes(mood: Mood | string): TriggerBuilder;
|
|
60
|
+
/**
|
|
61
|
+
* Set the NPC's disposition toward an entity when this trigger fires.
|
|
62
|
+
*
|
|
63
|
+
* @param entityId - Target entity
|
|
64
|
+
* @param word - Disposition word
|
|
65
|
+
* @returns this for chaining
|
|
66
|
+
*/
|
|
67
|
+
feelsAbout(entityId: string, word: DispositionWord): TriggerBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* Set the NPC's threat level when this trigger fires.
|
|
70
|
+
*
|
|
71
|
+
* @param level - Threat level word or numeric delta prefixed with + or -
|
|
72
|
+
* @returns this for chaining
|
|
73
|
+
*/
|
|
74
|
+
shift(dimension: 'threat', level: ThreatLevel): TriggerBuilder;
|
|
75
|
+
/**
|
|
76
|
+
* Enter a lucid window when this trigger fires.
|
|
77
|
+
*
|
|
78
|
+
* @returns this for chaining
|
|
79
|
+
*/
|
|
80
|
+
becomesLucid(): TriggerBuilder;
|
|
81
|
+
/**
|
|
82
|
+
* Finalize this trigger and return the parent builder.
|
|
83
|
+
*
|
|
84
|
+
* @returns The parent CharacterBuilder
|
|
85
|
+
*/
|
|
86
|
+
done(): CharacterBuilder;
|
|
87
|
+
/**
|
|
88
|
+
* Start a new trigger, auto-finalizing this one.
|
|
89
|
+
* Allows chaining `.on()` directly from a trigger without calling `.done()`.
|
|
90
|
+
*
|
|
91
|
+
* @param triggerName - Event type or condition name for the next trigger
|
|
92
|
+
* @returns A new TriggerBuilder
|
|
93
|
+
*/
|
|
94
|
+
on(triggerName: string): TriggerBuilder;
|
|
95
|
+
/**
|
|
96
|
+
* Compile the builder, auto-finalizing this trigger.
|
|
97
|
+
* Allows calling `.compile()` directly from a trigger chain.
|
|
98
|
+
*
|
|
99
|
+
* @returns Compiled character data
|
|
100
|
+
*/
|
|
101
|
+
compile(): CompiledCharacter;
|
|
102
|
+
/** @internal Get the compiled trigger without finalizing. */
|
|
103
|
+
_getTrigger(): CompiledTrigger;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Fluent builder for defining NPC characters.
|
|
107
|
+
*
|
|
108
|
+
* Accumulates character state declarations and compiles them into
|
|
109
|
+
* CharacterModelTrait constructor data, event handler functions,
|
|
110
|
+
* and state mutation rules.
|
|
111
|
+
*/
|
|
112
|
+
export declare class CharacterBuilder {
|
|
113
|
+
private _id;
|
|
114
|
+
private _personality;
|
|
115
|
+
private _dispositions;
|
|
116
|
+
private _mood;
|
|
117
|
+
private _threat;
|
|
118
|
+
private _cognitiveProfile;
|
|
119
|
+
private _knowledge;
|
|
120
|
+
private _beliefs;
|
|
121
|
+
private _goals;
|
|
122
|
+
private _lucidityConfig?;
|
|
123
|
+
private _perceptionFilters?;
|
|
124
|
+
private _perceivedEvents;
|
|
125
|
+
private _triggers;
|
|
126
|
+
private _customPredicates;
|
|
127
|
+
private _activeTriggerBuilder?;
|
|
128
|
+
private _vocabExtension?;
|
|
129
|
+
/**
|
|
130
|
+
* Create a new character builder.
|
|
131
|
+
*
|
|
132
|
+
* @param id - Character identifier (matches the NPC entity ID)
|
|
133
|
+
*/
|
|
134
|
+
constructor(id: string);
|
|
135
|
+
/** The character ID. */
|
|
136
|
+
get id(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Set personality traits.
|
|
139
|
+
*
|
|
140
|
+
* @param traits - Personality expressions like 'very honest', 'cowardly'
|
|
141
|
+
* @returns this for chaining
|
|
142
|
+
*/
|
|
143
|
+
personality(...traits: (PersonalityExpr | string)[]): CharacterBuilder;
|
|
144
|
+
/**
|
|
145
|
+
* Set disposition toward an entity using a word.
|
|
146
|
+
*
|
|
147
|
+
* @param entityId - Target entity
|
|
148
|
+
* @param word - Disposition word
|
|
149
|
+
* @returns this for chaining
|
|
150
|
+
*/
|
|
151
|
+
dispositionToward(entityId: string, word: DispositionWord): CharacterBuilder;
|
|
152
|
+
/** Shorthand: set disposition toward entity to 'devoted to'. */
|
|
153
|
+
loyalTo(entityId: string): CharacterBuilder;
|
|
154
|
+
/** Shorthand: set disposition toward entity to 'likes'. */
|
|
155
|
+
likes(entityId: string): CharacterBuilder;
|
|
156
|
+
/** Shorthand: set disposition toward entity to 'trusts'. */
|
|
157
|
+
trusts(entityId: string): CharacterBuilder;
|
|
158
|
+
/** Shorthand: set disposition toward entity to 'dislikes'. */
|
|
159
|
+
dislikes(entityId: string): CharacterBuilder;
|
|
160
|
+
/** Shorthand: set disposition toward entity to 'wary of'. */
|
|
161
|
+
distrusts(entityId: string): CharacterBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* Set the starting mood.
|
|
164
|
+
*
|
|
165
|
+
* @param word - Mood word
|
|
166
|
+
* @returns this for chaining
|
|
167
|
+
*/
|
|
168
|
+
mood(word: Mood | string): CharacterBuilder;
|
|
169
|
+
/**
|
|
170
|
+
* Set the starting threat level.
|
|
171
|
+
*
|
|
172
|
+
* @param level - Threat level word
|
|
173
|
+
* @returns this for chaining
|
|
174
|
+
*/
|
|
175
|
+
threat(level: ThreatLevel): CharacterBuilder;
|
|
176
|
+
/**
|
|
177
|
+
* Set the cognitive profile from a named preset or partial override.
|
|
178
|
+
*
|
|
179
|
+
* @param profile - A preset name string or partial CognitiveProfile object
|
|
180
|
+
* @returns this for chaining
|
|
181
|
+
*/
|
|
182
|
+
cognitiveProfile(profile: CognitivePresetName | string | Partial<CognitiveProfile>): CharacterBuilder;
|
|
183
|
+
/**
|
|
184
|
+
* Declare that the NPC knows about a topic.
|
|
185
|
+
*
|
|
186
|
+
* @param topic - What the NPC knows about
|
|
187
|
+
* @param opts - Optional: how they know and how confident
|
|
188
|
+
* @returns this for chaining
|
|
189
|
+
*/
|
|
190
|
+
knows(topic: string, opts?: {
|
|
191
|
+
witnessed?: boolean;
|
|
192
|
+
confidence?: ConfidenceWord;
|
|
193
|
+
}): CharacterBuilder;
|
|
194
|
+
/**
|
|
195
|
+
* Declare a belief the NPC holds (may differ from facts).
|
|
196
|
+
*
|
|
197
|
+
* @param topic - What the belief is about
|
|
198
|
+
* @param opts - Strength and resistance
|
|
199
|
+
* @returns this for chaining
|
|
200
|
+
*/
|
|
201
|
+
believes(topic: string, opts?: {
|
|
202
|
+
strength?: ConfidenceWord;
|
|
203
|
+
resistance?: 'none' | 'reinterprets' | 'ignores';
|
|
204
|
+
}): CharacterBuilder;
|
|
205
|
+
/**
|
|
206
|
+
* Add a goal with priority.
|
|
207
|
+
*
|
|
208
|
+
* @param id - Goal identifier
|
|
209
|
+
* @param priority - Numeric priority (higher = more important)
|
|
210
|
+
* @returns this for chaining
|
|
211
|
+
*/
|
|
212
|
+
goal(id: string, priority: number): CharacterBuilder;
|
|
213
|
+
/**
|
|
214
|
+
* Configure lucidity windows.
|
|
215
|
+
*
|
|
216
|
+
* @param config - Lucidity window configuration
|
|
217
|
+
* @returns this for chaining
|
|
218
|
+
*/
|
|
219
|
+
lucidity(config: LucidityConfig): CharacterBuilder;
|
|
220
|
+
/**
|
|
221
|
+
* Configure perception filters (for filtered perception).
|
|
222
|
+
*
|
|
223
|
+
* @param config - Categories to miss and amplify
|
|
224
|
+
* @returns this for chaining
|
|
225
|
+
*/
|
|
226
|
+
filters(config: PerceptionFilterConfig): CharacterBuilder;
|
|
227
|
+
/**
|
|
228
|
+
* Define a hallucinated perceived event (for augmented perception).
|
|
229
|
+
*
|
|
230
|
+
* @param topic - Topic of the hallucinated event
|
|
231
|
+
* @param opts - When it occurs and how it's stored
|
|
232
|
+
* @returns this for chaining
|
|
233
|
+
*/
|
|
234
|
+
perceives(topic: string, opts: PerceivedEvent): CharacterBuilder;
|
|
235
|
+
/**
|
|
236
|
+
* Begin a trigger chain for a named event or condition.
|
|
237
|
+
*
|
|
238
|
+
* @param triggerName - Event type or condition name
|
|
239
|
+
* @returns A TriggerBuilder for fluent chaining
|
|
240
|
+
*/
|
|
241
|
+
on(triggerName: string): TriggerBuilder;
|
|
242
|
+
/** @internal Called by TriggerBuilder.done() to register and clear the active trigger. */
|
|
243
|
+
_finalizeTrigger(trigger: CompiledTrigger): void;
|
|
244
|
+
/** @internal Kept for backward compat — delegates to _finalizeTrigger. */
|
|
245
|
+
_addTrigger(trigger: CompiledTrigger): void;
|
|
246
|
+
/** @internal Finalize any pending trigger builder that wasn't explicitly done(). */
|
|
247
|
+
private _finalizePendingTrigger;
|
|
248
|
+
/**
|
|
249
|
+
* Register a custom predicate function.
|
|
250
|
+
*
|
|
251
|
+
* @param name - Predicate name
|
|
252
|
+
* @param fn - Function that evaluates against CharacterModelTrait state
|
|
253
|
+
* @returns this for chaining
|
|
254
|
+
*/
|
|
255
|
+
definePredicate(name: string, fn: CharacterPredicate): CharacterBuilder;
|
|
256
|
+
/**
|
|
257
|
+
* Attach a vocabulary extension for story-specific words.
|
|
258
|
+
*
|
|
259
|
+
* @param ext - VocabularyExtension instance
|
|
260
|
+
* @returns this for chaining
|
|
261
|
+
*/
|
|
262
|
+
withVocabulary(ext: VocabularyExtension): CharacterBuilder;
|
|
263
|
+
/**
|
|
264
|
+
* Compile the builder state into CharacterModelTrait constructor data,
|
|
265
|
+
* compiled event handlers, and custom predicates.
|
|
266
|
+
*
|
|
267
|
+
* @returns Compiled character data
|
|
268
|
+
*/
|
|
269
|
+
compile(): CompiledCharacter;
|
|
270
|
+
}
|
|
271
|
+
/** The output of CharacterBuilder.compile(). */
|
|
272
|
+
export interface CompiledCharacter {
|
|
273
|
+
/** Character ID. */
|
|
274
|
+
id: string;
|
|
275
|
+
/** Data for constructing CharacterModelTrait. */
|
|
276
|
+
traitData: ICharacterModelData;
|
|
277
|
+
/** Compiled trigger rules for event-driven state mutations. */
|
|
278
|
+
triggers: CompiledTrigger[];
|
|
279
|
+
/** Custom predicates to register on the trait after construction. */
|
|
280
|
+
customPredicates: Map<string, CharacterPredicate>;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=character-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"character-builder.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/character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B;IAKzD;;;;;;OAMG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,gBAAgB;IAShE;;;;;OAKG;IACH,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc;IASvC,0FAA0F;IAC1F,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAKhD,0EAA0E;IAC1E,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAI3C,oFAAoF;IACpF,OAAO,CAAC,uBAAuB;IAU/B;;;;;;OAMG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,kBAAkB,GAAG,gBAAgB;IASvE;;;;;OAKG;IACH,cAAc,CAAC,GAAG,EAAE,mBAAmB,GAAG,gBAAgB;IAS1D;;;;;OAKG;IACH,OAAO,IAAI,iBAAiB;CAiF7B;AAMD,gDAAgD;AAChD,MAAM,WAAW,iBAAiB;IAChC,oBAAoB;IACpB,EAAE,EAAE,MAAM,CAAC;IAEX,iDAAiD;IACjD,SAAS,EAAE,mBAAmB,CAAC;IAE/B,+DAA+D;IAC/D,QAAQ,EAAE,eAAe,EAAE,CAAC;IAE5B,qEAAqE;IACrE,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fluent character builder (ADR-141)
|
|
4
|
+
*
|
|
5
|
+
* Authors describe characters in words; the builder accumulates state
|
|
6
|
+
* and compiles it into CharacterModelTrait data, event handlers, and
|
|
7
|
+
* state mutation rules.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: CharacterBuilder, TriggerBuilder.
|
|
10
|
+
* Owner context: @sharpee/character
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.CharacterBuilder = exports.TriggerBuilder = void 0;
|
|
14
|
+
const world_model_1 = require("../world-model/index.js");
|
|
15
|
+
const cognitive_presets_1 = require("./cognitive-presets");
|
|
16
|
+
/**
|
|
17
|
+
* Fluent chain for defining state transitions on triggers.
|
|
18
|
+
*
|
|
19
|
+
* Usage: `builder.on('player threatens').becomes('panicked').feelsAbout('player', 'wary of')`
|
|
20
|
+
*/
|
|
21
|
+
class TriggerBuilder {
|
|
22
|
+
trigger;
|
|
23
|
+
parentBuilder;
|
|
24
|
+
constructor(triggerName, parent) {
|
|
25
|
+
this.trigger = { triggerName, mutations: [] };
|
|
26
|
+
this.parentBuilder = parent;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Add a condition predicate to this trigger.
|
|
30
|
+
*
|
|
31
|
+
* @param predicate - Predicate name that must be true for this trigger to fire
|
|
32
|
+
* @returns this for chaining
|
|
33
|
+
*/
|
|
34
|
+
if(predicate) {
|
|
35
|
+
this.trigger.condition = predicate;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Set the NPC's mood when this trigger fires.
|
|
40
|
+
*
|
|
41
|
+
* @param mood - Mood word
|
|
42
|
+
* @returns this for chaining
|
|
43
|
+
*/
|
|
44
|
+
becomes(mood) {
|
|
45
|
+
this.trigger.mutations.push({ type: 'setMood', mood });
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Set the NPC's disposition toward an entity when this trigger fires.
|
|
50
|
+
*
|
|
51
|
+
* @param entityId - Target entity
|
|
52
|
+
* @param word - Disposition word
|
|
53
|
+
* @returns this for chaining
|
|
54
|
+
*/
|
|
55
|
+
feelsAbout(entityId, word) {
|
|
56
|
+
this.trigger.mutations.push({ type: 'setDisposition', entityId, word });
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set the NPC's threat level when this trigger fires.
|
|
61
|
+
*
|
|
62
|
+
* @param level - Threat level word or numeric delta prefixed with + or -
|
|
63
|
+
* @returns this for chaining
|
|
64
|
+
*/
|
|
65
|
+
shift(dimension, level) {
|
|
66
|
+
this.trigger.mutations.push({ type: 'setThreat', level });
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Enter a lucid window when this trigger fires.
|
|
71
|
+
*
|
|
72
|
+
* @returns this for chaining
|
|
73
|
+
*/
|
|
74
|
+
becomesLucid() {
|
|
75
|
+
this.trigger.mutations.push({ type: 'becomesLucid' });
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Finalize this trigger and return the parent builder.
|
|
80
|
+
*
|
|
81
|
+
* @returns The parent CharacterBuilder
|
|
82
|
+
*/
|
|
83
|
+
done() {
|
|
84
|
+
this.parentBuilder._finalizeTrigger(this.trigger);
|
|
85
|
+
return this.parentBuilder;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Start a new trigger, auto-finalizing this one.
|
|
89
|
+
* Allows chaining `.on()` directly from a trigger without calling `.done()`.
|
|
90
|
+
*
|
|
91
|
+
* @param triggerName - Event type or condition name for the next trigger
|
|
92
|
+
* @returns A new TriggerBuilder
|
|
93
|
+
*/
|
|
94
|
+
on(triggerName) {
|
|
95
|
+
return this.done().on(triggerName);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Compile the builder, auto-finalizing this trigger.
|
|
99
|
+
* Allows calling `.compile()` directly from a trigger chain.
|
|
100
|
+
*
|
|
101
|
+
* @returns Compiled character data
|
|
102
|
+
*/
|
|
103
|
+
compile() {
|
|
104
|
+
return this.done().compile();
|
|
105
|
+
}
|
|
106
|
+
/** @internal Get the compiled trigger without finalizing. */
|
|
107
|
+
_getTrigger() {
|
|
108
|
+
return this.trigger;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.TriggerBuilder = TriggerBuilder;
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// Character builder
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
/**
|
|
116
|
+
* Fluent builder for defining NPC characters.
|
|
117
|
+
*
|
|
118
|
+
* Accumulates character state declarations and compiles them into
|
|
119
|
+
* CharacterModelTrait constructor data, event handler functions,
|
|
120
|
+
* and state mutation rules.
|
|
121
|
+
*/
|
|
122
|
+
class CharacterBuilder {
|
|
123
|
+
_id;
|
|
124
|
+
_personality = new Map();
|
|
125
|
+
_dispositions = new Map();
|
|
126
|
+
_mood = 'calm';
|
|
127
|
+
_threat = 'safe';
|
|
128
|
+
_cognitiveProfile = { ...world_model_1.STABLE_COGNITIVE_PROFILE };
|
|
129
|
+
_knowledge = new Map();
|
|
130
|
+
_beliefs = new Map();
|
|
131
|
+
_goals = new Map();
|
|
132
|
+
_lucidityConfig;
|
|
133
|
+
_perceptionFilters;
|
|
134
|
+
_perceivedEvents = new Map();
|
|
135
|
+
_triggers = [];
|
|
136
|
+
_customPredicates = new Map();
|
|
137
|
+
_activeTriggerBuilder;
|
|
138
|
+
_vocabExtension;
|
|
139
|
+
/**
|
|
140
|
+
* Create a new character builder.
|
|
141
|
+
*
|
|
142
|
+
* @param id - Character identifier (matches the NPC entity ID)
|
|
143
|
+
*/
|
|
144
|
+
constructor(id) {
|
|
145
|
+
this._id = id;
|
|
146
|
+
}
|
|
147
|
+
/** The character ID. */
|
|
148
|
+
get id() {
|
|
149
|
+
return this._id;
|
|
150
|
+
}
|
|
151
|
+
// =========================================================================
|
|
152
|
+
// Personality
|
|
153
|
+
// =========================================================================
|
|
154
|
+
/**
|
|
155
|
+
* Set personality traits.
|
|
156
|
+
*
|
|
157
|
+
* @param traits - Personality expressions like 'very honest', 'cowardly'
|
|
158
|
+
* @returns this for chaining
|
|
159
|
+
*/
|
|
160
|
+
personality(...traits) {
|
|
161
|
+
for (const expr of traits) {
|
|
162
|
+
const [trait, value] = (0, world_model_1.parsePersonalityExpr)(expr);
|
|
163
|
+
this._personality.set(trait, value);
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
// =========================================================================
|
|
168
|
+
// Disposition shortcuts
|
|
169
|
+
// =========================================================================
|
|
170
|
+
/**
|
|
171
|
+
* Set disposition toward an entity using a word.
|
|
172
|
+
*
|
|
173
|
+
* @param entityId - Target entity
|
|
174
|
+
* @param word - Disposition word
|
|
175
|
+
* @returns this for chaining
|
|
176
|
+
*/
|
|
177
|
+
dispositionToward(entityId, word) {
|
|
178
|
+
this._dispositions.set(entityId, (0, world_model_1.dispositionToValue)(word));
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
/** Shorthand: set disposition toward entity to 'devoted to'. */
|
|
182
|
+
loyalTo(entityId) {
|
|
183
|
+
return this.dispositionToward(entityId, 'devoted to');
|
|
184
|
+
}
|
|
185
|
+
/** Shorthand: set disposition toward entity to 'likes'. */
|
|
186
|
+
likes(entityId) {
|
|
187
|
+
return this.dispositionToward(entityId, 'likes');
|
|
188
|
+
}
|
|
189
|
+
/** Shorthand: set disposition toward entity to 'trusts'. */
|
|
190
|
+
trusts(entityId) {
|
|
191
|
+
return this.dispositionToward(entityId, 'trusts');
|
|
192
|
+
}
|
|
193
|
+
/** Shorthand: set disposition toward entity to 'dislikes'. */
|
|
194
|
+
dislikes(entityId) {
|
|
195
|
+
return this.dispositionToward(entityId, 'dislikes');
|
|
196
|
+
}
|
|
197
|
+
/** Shorthand: set disposition toward entity to 'wary of'. */
|
|
198
|
+
distrusts(entityId) {
|
|
199
|
+
return this.dispositionToward(entityId, 'wary of');
|
|
200
|
+
}
|
|
201
|
+
// =========================================================================
|
|
202
|
+
// Mood
|
|
203
|
+
// =========================================================================
|
|
204
|
+
/**
|
|
205
|
+
* Set the starting mood.
|
|
206
|
+
*
|
|
207
|
+
* @param word - Mood word
|
|
208
|
+
* @returns this for chaining
|
|
209
|
+
*/
|
|
210
|
+
mood(word) {
|
|
211
|
+
this._mood = word;
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
// =========================================================================
|
|
215
|
+
// Threat
|
|
216
|
+
// =========================================================================
|
|
217
|
+
/**
|
|
218
|
+
* Set the starting threat level.
|
|
219
|
+
*
|
|
220
|
+
* @param level - Threat level word
|
|
221
|
+
* @returns this for chaining
|
|
222
|
+
*/
|
|
223
|
+
threat(level) {
|
|
224
|
+
this._threat = level;
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
// =========================================================================
|
|
228
|
+
// Cognitive profile
|
|
229
|
+
// =========================================================================
|
|
230
|
+
/**
|
|
231
|
+
* Set the cognitive profile from a named preset or partial override.
|
|
232
|
+
*
|
|
233
|
+
* @param profile - A preset name string or partial CognitiveProfile object
|
|
234
|
+
* @returns this for chaining
|
|
235
|
+
*/
|
|
236
|
+
cognitiveProfile(profile) {
|
|
237
|
+
if (typeof profile === 'string') {
|
|
238
|
+
if ((0, cognitive_presets_1.isCognitivePreset)(profile)) {
|
|
239
|
+
this._cognitiveProfile = { ...cognitive_presets_1.COGNITIVE_PRESETS[profile] };
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
throw new Error(`Unknown cognitive preset: '${profile}'. Available: ${Object.keys(cognitive_presets_1.COGNITIVE_PRESETS).join(', ')}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this._cognitiveProfile = { ...world_model_1.STABLE_COGNITIVE_PROFILE, ...profile };
|
|
247
|
+
}
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
// =========================================================================
|
|
251
|
+
// Knowledge
|
|
252
|
+
// =========================================================================
|
|
253
|
+
/**
|
|
254
|
+
* Declare that the NPC knows about a topic.
|
|
255
|
+
*
|
|
256
|
+
* @param topic - What the NPC knows about
|
|
257
|
+
* @param opts - Optional: how they know and how confident
|
|
258
|
+
* @returns this for chaining
|
|
259
|
+
*/
|
|
260
|
+
knows(topic, opts) {
|
|
261
|
+
this._knowledge.set(topic, {
|
|
262
|
+
source: opts?.witnessed ? 'witnessed' : 'assumed',
|
|
263
|
+
confidence: opts?.confidence ?? 'believes',
|
|
264
|
+
turn: 0,
|
|
265
|
+
});
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
// =========================================================================
|
|
269
|
+
// Beliefs
|
|
270
|
+
// =========================================================================
|
|
271
|
+
/**
|
|
272
|
+
* Declare a belief the NPC holds (may differ from facts).
|
|
273
|
+
*
|
|
274
|
+
* @param topic - What the belief is about
|
|
275
|
+
* @param opts - Strength and resistance
|
|
276
|
+
* @returns this for chaining
|
|
277
|
+
*/
|
|
278
|
+
believes(topic, opts) {
|
|
279
|
+
this._beliefs.set(topic, {
|
|
280
|
+
strength: opts?.strength ?? 'believes',
|
|
281
|
+
resistance: opts?.resistance ?? 'none',
|
|
282
|
+
});
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
// =========================================================================
|
|
286
|
+
// Goals
|
|
287
|
+
// =========================================================================
|
|
288
|
+
/**
|
|
289
|
+
* Add a goal with priority.
|
|
290
|
+
*
|
|
291
|
+
* @param id - Goal identifier
|
|
292
|
+
* @param priority - Numeric priority (higher = more important)
|
|
293
|
+
* @returns this for chaining
|
|
294
|
+
*/
|
|
295
|
+
goal(id, priority) {
|
|
296
|
+
this._goals.set(id, priority);
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
// =========================================================================
|
|
300
|
+
// Lucidity
|
|
301
|
+
// =========================================================================
|
|
302
|
+
/**
|
|
303
|
+
* Configure lucidity windows.
|
|
304
|
+
*
|
|
305
|
+
* @param config - Lucidity window configuration
|
|
306
|
+
* @returns this for chaining
|
|
307
|
+
*/
|
|
308
|
+
lucidity(config) {
|
|
309
|
+
this._lucidityConfig = config;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
// =========================================================================
|
|
313
|
+
// Perception
|
|
314
|
+
// =========================================================================
|
|
315
|
+
/**
|
|
316
|
+
* Configure perception filters (for filtered perception).
|
|
317
|
+
*
|
|
318
|
+
* @param config - Categories to miss and amplify
|
|
319
|
+
* @returns this for chaining
|
|
320
|
+
*/
|
|
321
|
+
filters(config) {
|
|
322
|
+
this._perceptionFilters = config;
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Define a hallucinated perceived event (for augmented perception).
|
|
327
|
+
*
|
|
328
|
+
* @param topic - Topic of the hallucinated event
|
|
329
|
+
* @param opts - When it occurs and how it's stored
|
|
330
|
+
* @returns this for chaining
|
|
331
|
+
*/
|
|
332
|
+
perceives(topic, opts) {
|
|
333
|
+
this._perceivedEvents.set(topic, opts);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
// =========================================================================
|
|
337
|
+
// Triggers (.on() chains)
|
|
338
|
+
// =========================================================================
|
|
339
|
+
/**
|
|
340
|
+
* Begin a trigger chain for a named event or condition.
|
|
341
|
+
*
|
|
342
|
+
* @param triggerName - Event type or condition name
|
|
343
|
+
* @returns A TriggerBuilder for fluent chaining
|
|
344
|
+
*/
|
|
345
|
+
on(triggerName) {
|
|
346
|
+
// Finalize any pending trigger builder
|
|
347
|
+
this._finalizePendingTrigger();
|
|
348
|
+
const tb = new TriggerBuilder(triggerName, this);
|
|
349
|
+
this._activeTriggerBuilder = tb;
|
|
350
|
+
return tb;
|
|
351
|
+
}
|
|
352
|
+
/** @internal Called by TriggerBuilder.done() to register and clear the active trigger. */
|
|
353
|
+
_finalizeTrigger(trigger) {
|
|
354
|
+
this._triggers.push(trigger);
|
|
355
|
+
this._activeTriggerBuilder = undefined;
|
|
356
|
+
}
|
|
357
|
+
/** @internal Kept for backward compat — delegates to _finalizeTrigger. */
|
|
358
|
+
_addTrigger(trigger) {
|
|
359
|
+
this._finalizeTrigger(trigger);
|
|
360
|
+
}
|
|
361
|
+
/** @internal Finalize any pending trigger builder that wasn't explicitly done(). */
|
|
362
|
+
_finalizePendingTrigger() {
|
|
363
|
+
if (this._activeTriggerBuilder) {
|
|
364
|
+
this._finalizeTrigger(this._activeTriggerBuilder._getTrigger());
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// =========================================================================
|
|
368
|
+
// Custom predicates
|
|
369
|
+
// =========================================================================
|
|
370
|
+
/**
|
|
371
|
+
* Register a custom predicate function.
|
|
372
|
+
*
|
|
373
|
+
* @param name - Predicate name
|
|
374
|
+
* @param fn - Function that evaluates against CharacterModelTrait state
|
|
375
|
+
* @returns this for chaining
|
|
376
|
+
*/
|
|
377
|
+
definePredicate(name, fn) {
|
|
378
|
+
this._customPredicates.set(name, fn);
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
// =========================================================================
|
|
382
|
+
// Vocabulary extension
|
|
383
|
+
// =========================================================================
|
|
384
|
+
/**
|
|
385
|
+
* Attach a vocabulary extension for story-specific words.
|
|
386
|
+
*
|
|
387
|
+
* @param ext - VocabularyExtension instance
|
|
388
|
+
* @returns this for chaining
|
|
389
|
+
*/
|
|
390
|
+
withVocabulary(ext) {
|
|
391
|
+
this._vocabExtension = ext;
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
// =========================================================================
|
|
395
|
+
// Compilation
|
|
396
|
+
// =========================================================================
|
|
397
|
+
/**
|
|
398
|
+
* Compile the builder state into CharacterModelTrait constructor data,
|
|
399
|
+
* compiled event handlers, and custom predicates.
|
|
400
|
+
*
|
|
401
|
+
* @returns Compiled character data
|
|
402
|
+
*/
|
|
403
|
+
compile() {
|
|
404
|
+
// Finalize any pending trigger
|
|
405
|
+
this._finalizePendingTrigger();
|
|
406
|
+
// Build personality record
|
|
407
|
+
const personality = {};
|
|
408
|
+
for (const [trait, value] of this._personality) {
|
|
409
|
+
personality[trait] = value;
|
|
410
|
+
}
|
|
411
|
+
// Build dispositions record
|
|
412
|
+
const dispositions = {};
|
|
413
|
+
for (const [entityId, value] of this._dispositions) {
|
|
414
|
+
dispositions[entityId] = value;
|
|
415
|
+
}
|
|
416
|
+
// Resolve mood — check custom vocabulary if not a platform mood
|
|
417
|
+
let moodWord = this._mood;
|
|
418
|
+
let moodValence;
|
|
419
|
+
let moodArousal;
|
|
420
|
+
if (!(this._mood in world_model_1.MOOD_AXES)) {
|
|
421
|
+
if (this._vocabExtension?.hasCustomMood(this._mood)) {
|
|
422
|
+
const custom = this._vocabExtension.getCustomMood(this._mood);
|
|
423
|
+
moodValence = custom.valence;
|
|
424
|
+
moodArousal = custom.arousal;
|
|
425
|
+
moodWord = undefined; // will use raw axes
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// Build knowledge record
|
|
429
|
+
const knowledge = {};
|
|
430
|
+
for (const [topic, fact] of this._knowledge) {
|
|
431
|
+
knowledge[topic] = { source: fact.source, confidence: fact.confidence, turnLearned: fact.turn };
|
|
432
|
+
}
|
|
433
|
+
// Build beliefs record
|
|
434
|
+
const beliefs = {};
|
|
435
|
+
for (const [topic, belief] of this._beliefs) {
|
|
436
|
+
beliefs[topic] = belief;
|
|
437
|
+
}
|
|
438
|
+
// Build goals array
|
|
439
|
+
const goals = Array.from(this._goals.entries())
|
|
440
|
+
.map(([id, priority]) => ({ id, priority }))
|
|
441
|
+
.sort((a, b) => b.priority - a.priority);
|
|
442
|
+
// Build perceived events
|
|
443
|
+
const perceivedEvents = {};
|
|
444
|
+
for (const [topic, pe] of this._perceivedEvents) {
|
|
445
|
+
perceivedEvents[topic] = pe;
|
|
446
|
+
}
|
|
447
|
+
// Assemble trait data
|
|
448
|
+
const traitData = {
|
|
449
|
+
personality: personality,
|
|
450
|
+
dispositions,
|
|
451
|
+
...(moodValence !== undefined
|
|
452
|
+
? { moodValence, moodArousal: moodArousal }
|
|
453
|
+
: { mood: moodWord }),
|
|
454
|
+
threat: this._threat,
|
|
455
|
+
cognitiveProfile: this._cognitiveProfile,
|
|
456
|
+
knowledge,
|
|
457
|
+
beliefs,
|
|
458
|
+
goals,
|
|
459
|
+
lucidityConfig: this._lucidityConfig,
|
|
460
|
+
currentLucidityState: this._lucidityConfig?.baseline,
|
|
461
|
+
perceptionFilters: this._perceptionFilters,
|
|
462
|
+
perceivedEvents,
|
|
463
|
+
};
|
|
464
|
+
// Collect custom predicates
|
|
465
|
+
const customPredicates = new Map(this._customPredicates);
|
|
466
|
+
return {
|
|
467
|
+
id: this._id,
|
|
468
|
+
traitData,
|
|
469
|
+
triggers: [...this._triggers],
|
|
470
|
+
customPredicates,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
exports.CharacterBuilder = CharacterBuilder;
|
|
475
|
+
//# sourceMappingURL=character-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"character-builder.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/character-builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,sDAmB8B;AAC9B,2DAAgG;AAsBhG;;;;GAIG;AACH,MAAa,cAAc;IACjB,OAAO,CAAkB;IACzB,aAAa,CAAmB;IAExC,YAAY,WAAmB,EAAE,MAAwB;QACvD,IAAI,CAAC,OAAO,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QAC9C,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,EAAE,CAAC,SAAiB;QAClB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,IAAmB;QACzB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,QAAgB,EAAE,IAAqB;QAChD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG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ACT,OAAO;YACP,KAAK;YACL,cAAc,EAAE,IAAI,CAAC,eAAe;YACpC,oBAAoB,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ;YACpD,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;YAC1C,eAAe;SAChB,CAAC;QAEF,4BAA4B;QAC5B,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzD,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,GAAG;YACZ,SAAS;YACT,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7B,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF;AAhZD,4CAgZC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named cognitive profile presets (ADR-141)
|
|
3
|
+
*
|
|
4
|
+
* Documented example profiles for common cognitive conditions.
|
|
5
|
+
* These are starting points for authors, not platform-level constants.
|
|
6
|
+
* Authors override any dimension via the builder's cognitiveProfile() method.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: COGNITIVE_PRESETS, CognitivePresetName.
|
|
9
|
+
* Owner context: @sharpee/character
|
|
10
|
+
*/
|
|
11
|
+
import { CognitiveProfile } from "../world-model/index";
|
|
12
|
+
/** Names of built-in cognitive presets. */
|
|
13
|
+
export type CognitivePresetName = 'stable' | 'schizophrenic' | 'ptsd' | 'dementia' | 'dissociative' | 'tbi' | 'obsessive' | 'intoxicated';
|
|
14
|
+
/**
|
|
15
|
+
* Named cognitive profile presets.
|
|
16
|
+
*
|
|
17
|
+
* Each maps to the five-dimensional profile from ADR-141's condition table.
|
|
18
|
+
* Authors select a preset as a starting point, then override individual
|
|
19
|
+
* dimensions as needed for their character.
|
|
20
|
+
*/
|
|
21
|
+
export declare const COGNITIVE_PRESETS: Record<CognitivePresetName, CognitiveProfile>;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a string is a valid cognitive preset name.
|
|
24
|
+
*
|
|
25
|
+
* @param name - String to check
|
|
26
|
+
* @returns True if the name is a recognized preset
|
|
27
|
+
*/
|
|
28
|
+
export declare function isCognitivePreset(name: string): name is CognitivePresetName;
|
|
29
|
+
//# sourceMappingURL=cognitive-presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognitive-presets.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/character/src/cognitive-presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,2CAA2C;AAC3C,MAAM,MAAM,mBAAmB,GAC3B,QAAQ,GACR,eAAe,GACf,MAAM,GACN,UAAU,GACV,cAAc,GACd,KAAK,GACL,WAAW,GACX,aAAa,CAAC;AAElB;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAyD3E,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,mBAAmB,CAE3E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Named cognitive profile presets (ADR-141)
|
|
4
|
+
*
|
|
5
|
+
* Documented example profiles for common cognitive conditions.
|
|
6
|
+
* These are starting points for authors, not platform-level constants.
|
|
7
|
+
* Authors override any dimension via the builder's cognitiveProfile() method.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: COGNITIVE_PRESETS, CognitivePresetName.
|
|
10
|
+
* Owner context: @sharpee/character
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.COGNITIVE_PRESETS = void 0;
|
|
14
|
+
exports.isCognitivePreset = isCognitivePreset;
|
|
15
|
+
/**
|
|
16
|
+
* Named cognitive profile presets.
|
|
17
|
+
*
|
|
18
|
+
* Each maps to the five-dimensional profile from ADR-141's condition table.
|
|
19
|
+
* Authors select a preset as a starting point, then override individual
|
|
20
|
+
* dimensions as needed for their character.
|
|
21
|
+
*/
|
|
22
|
+
exports.COGNITIVE_PRESETS = {
|
|
23
|
+
stable: {
|
|
24
|
+
perception: 'accurate',
|
|
25
|
+
beliefFormation: 'flexible',
|
|
26
|
+
coherence: 'focused',
|
|
27
|
+
lucidity: 'stable',
|
|
28
|
+
selfModel: 'intact',
|
|
29
|
+
},
|
|
30
|
+
schizophrenic: {
|
|
31
|
+
perception: 'augmented',
|
|
32
|
+
beliefFormation: 'resistant',
|
|
33
|
+
coherence: 'fragmented',
|
|
34
|
+
lucidity: 'episodic',
|
|
35
|
+
selfModel: 'uncertain',
|
|
36
|
+
},
|
|
37
|
+
ptsd: {
|
|
38
|
+
perception: 'filtered',
|
|
39
|
+
beliefFormation: 'rigid',
|
|
40
|
+
coherence: 'drifting',
|
|
41
|
+
lucidity: 'episodic',
|
|
42
|
+
selfModel: 'uncertain',
|
|
43
|
+
},
|
|
44
|
+
dementia: {
|
|
45
|
+
perception: 'filtered',
|
|
46
|
+
beliefFormation: 'rigid',
|
|
47
|
+
coherence: 'fragmented',
|
|
48
|
+
lucidity: 'fluctuating',
|
|
49
|
+
selfModel: 'fractured',
|
|
50
|
+
},
|
|
51
|
+
dissociative: {
|
|
52
|
+
perception: 'accurate',
|
|
53
|
+
beliefFormation: 'flexible',
|
|
54
|
+
coherence: 'focused',
|
|
55
|
+
lucidity: 'episodic',
|
|
56
|
+
selfModel: 'fractured',
|
|
57
|
+
},
|
|
58
|
+
tbi: {
|
|
59
|
+
perception: 'filtered',
|
|
60
|
+
beliefFormation: 'flexible',
|
|
61
|
+
coherence: 'drifting',
|
|
62
|
+
lucidity: 'fluctuating',
|
|
63
|
+
selfModel: 'uncertain',
|
|
64
|
+
},
|
|
65
|
+
obsessive: {
|
|
66
|
+
perception: 'accurate',
|
|
67
|
+
beliefFormation: 'resistant',
|
|
68
|
+
coherence: 'focused',
|
|
69
|
+
lucidity: 'stable',
|
|
70
|
+
selfModel: 'intact',
|
|
71
|
+
},
|
|
72
|
+
intoxicated: {
|
|
73
|
+
perception: 'filtered',
|
|
74
|
+
beliefFormation: 'flexible',
|
|
75
|
+
coherence: 'drifting',
|
|
76
|
+
lucidity: 'fluctuating',
|
|
77
|
+
selfModel: 'intact',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Check if a string is a valid cognitive preset name.
|
|
82
|
+
*
|
|
83
|
+
* @param name - String to check
|
|
84
|
+
* @returns True if the name is a recognized preset
|
|
85
|
+
*/
|
|
86
|
+
function isCognitivePreset(name) {
|
|
87
|
+
return name in exports.COGNITIVE_PRESETS;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=cognitive-presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognitive-presets.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/cognitive-presets.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAuFH,8CAEC;AA1ED;;;;;;GAMG;AACU,QAAA,iBAAiB,GAAkD;IAC9E,MAAM,EAAE;QACN,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,UAAU;QAC3B,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,QAAQ;QAClB,SAAS,EAAE,QAAQ;KACpB;IACD,aAAa,EAAE;QACb,UAAU,EAAE,WAAW;QACvB,eAAe,EAAE,WAAW;QAC5B,SAAS,EAAE,YAAY;QACvB,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,WAAW;KACvB;IACD,IAAI,EAAE;QACJ,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,WAAW;KACvB;IACD,QAAQ,EAAE;QACR,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,YAAY;QACvB,QAAQ,EAAE,aAAa;QACvB,SAAS,EAAE,WAAW;KACvB;IACD,YAAY,EAAE;QACZ,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,UAAU;QAC3B,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,WAAW;KACvB;IACD,GAAG,EAAE;QACH,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,UAAU;QAC3B,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,aAAa;QACvB,SAAS,EAAE,WAAW;KACvB;IACD,SAAS,EAAE;QACT,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,WAAW;QAC5B,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,QAAQ;QAClB,SAAS,EAAE,QAAQ;KACpB;IACD,WAAW,EAAE;QACX,UAAU,EAAE,UAAU;QACtB,eAAe,EAAE,UAAU;QAC3B,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,aAAa;QACvB,SAAS,EAAE,QAAQ;KACpB;CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,IAAI,yBAAiB,CAAC;AACnC,CAAC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sharpee/character — Character model builder (ADR-141)
|
|
3
|
+
*
|
|
4
|
+
* Fluent builder API for defining NPC characters with rich internal state.
|
|
5
|
+
* Authors describe characters in words; the builder compiles to trait data
|
|
6
|
+
* consumed by CharacterModelTrait in @sharpee/world-model.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: CharacterBuilder, TriggerBuilder, CompiledCharacter,
|
|
9
|
+
* COGNITIVE_PRESETS, VocabularyExtension, applyCharacter.
|
|
10
|
+
* Owner context: @sharpee/character package
|
|
11
|
+
*/
|
|
12
|
+
export { CharacterBuilder, TriggerBuilder, type CompiledCharacter, type CompiledTrigger, type TriggerMutation, } from './character-builder';
|
|
13
|
+
export { COGNITIVE_PRESETS, isCognitivePreset, type CognitivePresetName, } from './cognitive-presets';
|
|
14
|
+
export { VocabularyExtension, type CustomMoodDef, type CustomPersonalityDef, } from './vocabulary-extension';
|
|
15
|
+
export { applyCharacter } from './apply';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/character/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @sharpee/character — Character model builder (ADR-141)
|
|
4
|
+
*
|
|
5
|
+
* Fluent builder API for defining NPC characters with rich internal state.
|
|
6
|
+
* Authors describe characters in words; the builder compiles to trait data
|
|
7
|
+
* consumed by CharacterModelTrait in @sharpee/world-model.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: CharacterBuilder, TriggerBuilder, CompiledCharacter,
|
|
10
|
+
* COGNITIVE_PRESETS, VocabularyExtension, applyCharacter.
|
|
11
|
+
* Owner context: @sharpee/character package
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.applyCharacter = exports.VocabularyExtension = exports.isCognitivePreset = exports.COGNITIVE_PRESETS = exports.TriggerBuilder = exports.CharacterBuilder = void 0;
|
|
15
|
+
var character_builder_1 = require("./character-builder");
|
|
16
|
+
Object.defineProperty(exports, "CharacterBuilder", { enumerable: true, get: function () { return character_builder_1.CharacterBuilder; } });
|
|
17
|
+
Object.defineProperty(exports, "TriggerBuilder", { enumerable: true, get: function () { return character_builder_1.TriggerBuilder; } });
|
|
18
|
+
var cognitive_presets_1 = require("./cognitive-presets");
|
|
19
|
+
Object.defineProperty(exports, "COGNITIVE_PRESETS", { enumerable: true, get: function () { return cognitive_presets_1.COGNITIVE_PRESETS; } });
|
|
20
|
+
Object.defineProperty(exports, "isCognitivePreset", { enumerable: true, get: function () { return cognitive_presets_1.isCognitivePreset; } });
|
|
21
|
+
var vocabulary_extension_1 = require("./vocabulary-extension");
|
|
22
|
+
Object.defineProperty(exports, "VocabularyExtension", { enumerable: true, get: function () { return vocabulary_extension_1.VocabularyExtension; } });
|
|
23
|
+
var apply_1 = require("./apply");
|
|
24
|
+
Object.defineProperty(exports, "applyCharacter", { enumerable: true, get: function () { return apply_1.applyCharacter; } });
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,yDAM6B;AAL3B,qHAAA,gBAAgB,OAAA;AAChB,mHAAA,cAAc,OAAA;AAMhB,yDAI6B;AAH3B,sHAAA,iBAAiB,OAAA;AACjB,sHAAA,iBAAiB,OAAA;AAInB,+DAIgC;AAH9B,2HAAA,mBAAmB,OAAA;AAKrB,iCAAyC;AAAhC,uGAAA,cAAc,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sharpee/character",
|
|
3
|
+
"version": "0.9.106",
|
|
4
|
+
"description": "Character model builder for Sharpee Interactive Fiction Platform (ADR-141)",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"require": "./index.js",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@sharpee/world-model": "^0.9.106",
|
|
16
|
+
"@sharpee/stdlib": "^0.9.106"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"interactive-fiction",
|
|
20
|
+
"if",
|
|
21
|
+
"text-adventure",
|
|
22
|
+
"sharpee",
|
|
23
|
+
"character",
|
|
24
|
+
"npc",
|
|
25
|
+
"builder"
|
|
26
|
+
],
|
|
27
|
+
"author": "Sharpee Team",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ChicagoDave/sharpee.git",
|
|
32
|
+
"directory": "packages/character"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Story-specific vocabulary extension (ADR-141)
|
|
3
|
+
*
|
|
4
|
+
* Allows stories to add custom mood words and personality traits
|
|
5
|
+
* beyond the platform defaults. Extended vocabulary is validated
|
|
6
|
+
* by the builder and compiled into trait data.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: VocabularyExtension, defineCustomMood, defineCustomPersonality.
|
|
9
|
+
* Owner context: @sharpee/character
|
|
10
|
+
*/
|
|
11
|
+
/** A custom mood definition with valence-arousal coordinates. */
|
|
12
|
+
export interface CustomMoodDef {
|
|
13
|
+
name: string;
|
|
14
|
+
valence: number;
|
|
15
|
+
arousal: number;
|
|
16
|
+
}
|
|
17
|
+
/** A custom personality trait definition. */
|
|
18
|
+
export interface CustomPersonalityDef {
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Registry of story-specific vocabulary extensions.
|
|
23
|
+
*
|
|
24
|
+
* Stories call defineCustomMood() and defineCustomPersonality()
|
|
25
|
+
* during initialization. The builder validates against both
|
|
26
|
+
* platform vocabulary and these extensions.
|
|
27
|
+
*/
|
|
28
|
+
export declare class VocabularyExtension {
|
|
29
|
+
private customMoods;
|
|
30
|
+
private customPersonalities;
|
|
31
|
+
/**
|
|
32
|
+
* Define a custom mood word with valence-arousal coordinates.
|
|
33
|
+
*
|
|
34
|
+
* @param name - The mood word (e.g., 'lovesick')
|
|
35
|
+
* @param valence - Valence value (-1 to 1)
|
|
36
|
+
* @param arousal - Arousal value (0 to 1)
|
|
37
|
+
*/
|
|
38
|
+
defineMood(name: string, valence: number, arousal: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Define a custom personality trait name.
|
|
41
|
+
*
|
|
42
|
+
* @param name - The personality trait (e.g., 'righteous')
|
|
43
|
+
*/
|
|
44
|
+
definePersonality(name: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a mood word is a recognized custom mood.
|
|
47
|
+
*
|
|
48
|
+
* @param name - Mood word to check
|
|
49
|
+
* @returns True if it was registered via defineMood()
|
|
50
|
+
*/
|
|
51
|
+
hasCustomMood(name: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get a custom mood definition.
|
|
54
|
+
*
|
|
55
|
+
* @param name - Mood word to look up
|
|
56
|
+
* @returns The mood definition, or undefined
|
|
57
|
+
*/
|
|
58
|
+
getCustomMood(name: string): CustomMoodDef | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a personality trait is a recognized custom trait.
|
|
61
|
+
*
|
|
62
|
+
* @param name - Personality trait to check
|
|
63
|
+
* @returns True if it was registered via definePersonality()
|
|
64
|
+
*/
|
|
65
|
+
hasCustomPersonality(name: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Get all registered custom mood names.
|
|
68
|
+
*
|
|
69
|
+
* @returns Array of custom mood names
|
|
70
|
+
*/
|
|
71
|
+
getCustomMoodNames(): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Get all registered custom personality names.
|
|
74
|
+
*
|
|
75
|
+
* @returns Array of custom personality trait names
|
|
76
|
+
*/
|
|
77
|
+
getCustomPersonalityNames(): string[];
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=vocabulary-extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary-extension.d.ts","sourceRoot":"","sources":["../../../../../repos/sharpee/packages/character/src/vocabulary-extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,WAAW,CAAyC;IAC5D,OAAO,CAAC,mBAAmB,CAA0B;IAErD;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIhE;;;;OAIG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIrC;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAItD;;;;;OAKG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI3C;;;;OAIG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;;;OAIG;IACH,yBAAyB,IAAI,MAAM,EAAE;CAGtC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Story-specific vocabulary extension (ADR-141)
|
|
4
|
+
*
|
|
5
|
+
* Allows stories to add custom mood words and personality traits
|
|
6
|
+
* beyond the platform defaults. Extended vocabulary is validated
|
|
7
|
+
* by the builder and compiled into trait data.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: VocabularyExtension, defineCustomMood, defineCustomPersonality.
|
|
10
|
+
* Owner context: @sharpee/character
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.VocabularyExtension = void 0;
|
|
14
|
+
/**
|
|
15
|
+
* Registry of story-specific vocabulary extensions.
|
|
16
|
+
*
|
|
17
|
+
* Stories call defineCustomMood() and defineCustomPersonality()
|
|
18
|
+
* during initialization. The builder validates against both
|
|
19
|
+
* platform vocabulary and these extensions.
|
|
20
|
+
*/
|
|
21
|
+
class VocabularyExtension {
|
|
22
|
+
customMoods = new Map();
|
|
23
|
+
customPersonalities = new Set();
|
|
24
|
+
/**
|
|
25
|
+
* Define a custom mood word with valence-arousal coordinates.
|
|
26
|
+
*
|
|
27
|
+
* @param name - The mood word (e.g., 'lovesick')
|
|
28
|
+
* @param valence - Valence value (-1 to 1)
|
|
29
|
+
* @param arousal - Arousal value (0 to 1)
|
|
30
|
+
*/
|
|
31
|
+
defineMood(name, valence, arousal) {
|
|
32
|
+
this.customMoods.set(name, { name, valence, arousal });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Define a custom personality trait name.
|
|
36
|
+
*
|
|
37
|
+
* @param name - The personality trait (e.g., 'righteous')
|
|
38
|
+
*/
|
|
39
|
+
definePersonality(name) {
|
|
40
|
+
this.customPersonalities.add(name);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if a mood word is a recognized custom mood.
|
|
44
|
+
*
|
|
45
|
+
* @param name - Mood word to check
|
|
46
|
+
* @returns True if it was registered via defineMood()
|
|
47
|
+
*/
|
|
48
|
+
hasCustomMood(name) {
|
|
49
|
+
return this.customMoods.has(name);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get a custom mood definition.
|
|
53
|
+
*
|
|
54
|
+
* @param name - Mood word to look up
|
|
55
|
+
* @returns The mood definition, or undefined
|
|
56
|
+
*/
|
|
57
|
+
getCustomMood(name) {
|
|
58
|
+
return this.customMoods.get(name);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a personality trait is a recognized custom trait.
|
|
62
|
+
*
|
|
63
|
+
* @param name - Personality trait to check
|
|
64
|
+
* @returns True if it was registered via definePersonality()
|
|
65
|
+
*/
|
|
66
|
+
hasCustomPersonality(name) {
|
|
67
|
+
return this.customPersonalities.has(name);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get all registered custom mood names.
|
|
71
|
+
*
|
|
72
|
+
* @returns Array of custom mood names
|
|
73
|
+
*/
|
|
74
|
+
getCustomMoodNames() {
|
|
75
|
+
return Array.from(this.customMoods.keys());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get all registered custom personality names.
|
|
79
|
+
*
|
|
80
|
+
* @returns Array of custom personality trait names
|
|
81
|
+
*/
|
|
82
|
+
getCustomPersonalityNames() {
|
|
83
|
+
return Array.from(this.customPersonalities);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.VocabularyExtension = VocabularyExtension;
|
|
87
|
+
//# sourceMappingURL=vocabulary-extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary-extension.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/vocabulary-extension.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAcH;;;;;;GAMG;AACH,MAAa,mBAAmB;IACtB,WAAW,GAA+B,IAAI,GAAG,EAAE,CAAC;IACpD,mBAAmB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAErD;;;;;;OAMG;IACH,UAAU,CAAC,IAAY,EAAE,OAAe,EAAE,OAAe;QACvD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,IAAY;QAC5B,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAAC,IAAY;QAC/B,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,kBAAkB;QAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACH,yBAAyB;QACvB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC9C,CAAC;CACF;AAvED,kDAuEC"}
|