-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtypes.ts
More file actions
452 lines (404 loc) · 17.5 KB
/
Copy pathtypes.ts
File metadata and controls
452 lines (404 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/**
* @module types
* Core type definitions for the Paracosm simulation engine.
* All types needed to define a ScenarioPackage and interact with the engine.
*/
import type { HexacoProfile, Agent, SimulationState } from './core/state.js';
import type { TraitProfile } from './traits/index.js';
// ---------------------------------------------------------------------------
// Primitive value types
// ---------------------------------------------------------------------------
/** Possible field values for agent/colonist custom fields. */
export type AgentFieldValue = number | string | boolean | string[];
// ---------------------------------------------------------------------------
// Scenario labels and theme
// ---------------------------------------------------------------------------
/** Human-readable labels for a scenario, used in UI and output naming. */
export interface ScenarioLabels {
/** Full display name (e.g., "Mars Genesis") */
name: string;
/** Short identifier used in file names and localStorage keys */
shortName: string;
/** What to call population members (e.g., "colonists", "crew members") */
populationNoun: string;
/** What to call the settlement (e.g., "colony", "outpost") */
settlementNoun: string;
/** Currency unit (e.g., "credits") */
currency: string;
/** What to call turn events (e.g., "crises", "events", "incidents", "scenarios"). Default: "events" */
eventNoun?: string;
/** What to call a single turn event (e.g., "crisis", "event", "incident"). Default: "event" */
eventNounSingular?: string;
/** Singular display word for one simulation time-unit (e.g., "year", "hour", "quarter", "tick"). Default when absent: "tick". */
timeUnitNoun?: string;
/** Plural form of `timeUnitNoun` (e.g., "years", "hours", "quarters", "ticks"). Default when absent: "ticks". */
timeUnitNounPlural?: string;
/**
* Singular display word for the swappable decision-making entity that
* runs each parallel counterfactual. Defaults to "actor" — the universal
* abstract type. Scenarios specialize it: Mars Genesis sets "commander",
* a hurricane scenario sets "incident commander", an AI release sets
* "release director", a quantum-game scenario sets "player". The
* engine type stays `ActorConfig` for SDK back-compat; this label is
* for UI / copy / button text rendering only.
*/
actorNoun?: string;
/** Plural form of `actorNoun`. Defaults to "actors". */
actorNounPlural?: string;
/**
* Optional one-line "what is this scenario about" copy surfaced on
* Quickstart cards and replay banners. Read by the LoadedScenarioCTA
* to give first-time visitors enough context to know what they're
* about to launch without having to dig into the JSON. Compact: <=
* 200 chars, plain text.
*/
tagline?: string;
}
/** Visual theme for a scenario. Applied to the dashboard via CSS custom properties. */
export interface ScenarioTheme {
primaryColor: string;
accentColor: string;
/** CSS custom properties injected into :root on scenario load */
cssVariables: Record<string, string>;
}
// ---------------------------------------------------------------------------
// Setup schema
// ---------------------------------------------------------------------------
/** Default values for the simulation setup form. */
export interface ScenarioSetupSchema {
defaultTurns: number;
defaultSeed: number;
defaultStartTime: number;
defaultTimePerTurn?: number;
defaultPopulation: number;
/** Maximum events the Event Director can generate per turn. Default: 3 */
maxEventsPerTurn?: number;
/** Which setup form sections to expose in the dashboard */
configurableSections: Array<'actors' | 'personnel' | 'resources' | 'departments' | 'events' | 'models' | 'advanced'>;
}
// ---------------------------------------------------------------------------
// World state schema
// ---------------------------------------------------------------------------
/** Schema for a single world metric, capacity, status, or political variable. */
export interface WorldMetricSchema {
id: string;
label: string;
unit: string;
type: 'number' | 'string' | 'boolean';
initial: number | string | boolean;
min?: number;
max?: number;
category: 'metric' | 'capacity' | 'status' | 'politic' | 'environment';
}
/** Declares all world state variables for a scenario. */
export interface ScenarioWorldSchema {
metrics: Record<string, WorldMetricSchema>;
capacities: Record<string, WorldMetricSchema>;
statuses: Record<string, WorldMetricSchema>;
politics: Record<string, WorldMetricSchema>;
environment: Record<string, WorldMetricSchema>;
}
/** Runtime world state with typed record bags. Not everything is a flat numeric resource. */
export interface WorldState {
/** Numeric gauges: food, power, water, population, morale */
metrics: Record<string, number>;
/** Capacity constraints: life support, housing */
capacities: Record<string, number>;
/** Categorical state: governance status, faction alignment */
statuses: Record<string, string | boolean>;
/** Political/social pressures */
politics: Record<string, number | string | boolean>;
/** Environment conditions */
environment: Record<string, number | string | boolean>;
}
// ---------------------------------------------------------------------------
// Agent field definitions
// ---------------------------------------------------------------------------
/** Defines a custom field on agents/colonists for a scenario. */
export interface AgentFieldDefinition {
id: string;
label: string;
unit: string;
type: 'number' | 'string' | 'boolean' | 'tags';
initial: AgentFieldValue;
min?: number;
max?: number;
mortalityContribution?: { threshold: number; ratePerYear: number };
showInTooltip: boolean;
includeInReactionContext: boolean;
}
// ---------------------------------------------------------------------------
// Department definitions
// ---------------------------------------------------------------------------
/** Defines a department (analysis group) in the scenario. */
export interface DepartmentDefinition {
id: string;
label: string;
role: string;
icon: string;
defaultModel: string;
instructions: string;
}
// ---------------------------------------------------------------------------
// Metrics, effects, events
// ---------------------------------------------------------------------------
/** Defines a derived metric displayed in the dashboard header. */
export interface MetricDefinition {
id: string;
label: string;
source: string;
format: 'number' | 'percent' | 'currency' | 'duration';
}
/** Defines an effect category with base deltas applied on crisis outcomes. */
export interface EffectDefinition {
id: string;
type: string;
label: string;
/** Maps crisis category to base colony system deltas */
categoryDefaults: Record<string, Record<string, number>>;
}
/** Defines an event type with render metadata for the dashboard. */
export interface EventDefinition {
id: string;
label: string;
icon: string;
color: string;
}
// ---------------------------------------------------------------------------
// UI schema
// ---------------------------------------------------------------------------
/** Tells the dashboard how to render scenario-specific UI elements. */
export interface ScenarioUiDefinition {
headerMetrics: Array<{ id: string; format: 'number' | 'percent' | 'currency' | 'duration' }>;
tooltipFields: string[];
reportSections: Array<'crisis' | 'departments' | 'decision' | 'outcome' | 'quotes' | 'causality'>;
departmentIcons: Record<string, string>;
eventRenderers: Record<string, { icon: string; color: string }>;
setupSections: Array<'actors' | 'personnel' | 'resources' | 'departments' | 'events' | 'models' | 'advanced'>;
}
// ---------------------------------------------------------------------------
// Knowledge bundle
// ---------------------------------------------------------------------------
/** A single research citation with optional DOI. */
export interface KnowledgeCitation {
claim: string;
source: string;
url: string;
doi?: string;
}
/** A research topic with facts, counterpoints, and department-specific notes. */
export interface KnowledgeTopic {
canonicalFacts: KnowledgeCitation[];
counterpoints: Array<{ claim: string; source: string; url: string }>;
departmentNotes: Record<string, string>;
}
/** Scenario-owned research knowledge organized by topic with crisis category mapping. */
export interface KnowledgeBundle {
topics: Record<string, KnowledgeTopic>;
/** Maps crisis category to relevant topic IDs */
categoryMapping: Record<string, string[]>;
}
// ---------------------------------------------------------------------------
// Policies
// ---------------------------------------------------------------------------
/** Feature policies controlling what capabilities are enabled for a scenario. */
export interface ScenarioPolicies {
toolForging: { enabled: boolean; requiredPerDepartment?: boolean };
liveSearch: { enabled: boolean; mode: 'off' | 'manual' | 'auto' };
bulletin: { enabled: boolean };
characterChat: { enabled: boolean };
sandbox: { timeoutMs: number; memoryMB: number };
}
// ---------------------------------------------------------------------------
// Presets
// ---------------------------------------------------------------------------
/** A product-level preset with pre-configured leaders, personnel, and starting state. */
export interface ScenarioPreset {
id: string;
label: string;
leaders?: Array<{ name: string; archetype: string; hexaco: Record<string, number>; instructions: string }>;
personnel?: Array<{ name: string; department: string; role: string; specialization: string; age: number; featured: boolean }>;
startingState?: Partial<WorldState>;
}
// ---------------------------------------------------------------------------
// Hooks
// ---------------------------------------------------------------------------
/** Context passed to the scenario progression hook during between-turn advancement. */
export interface ProgressionHookContext {
/** All agents (mutable: the hook modifies health fields in place) */
agents: Agent[];
timeDelta: number;
time: number;
turn: number;
startTime: number;
/** Seeded RNG for deterministic random operations */
rng: { chance(probability: number): boolean; next(): number; pick<T>(arr: readonly T[]): T; int(min: number, max: number): number };
}
/** Context passed to the scenario department prompt hook. */
export interface PromptHookContext {
department: string;
state: SimulationState;
scenario: Scenario;
researchPacket: { canonicalFacts: Array<{ claim: string; source: string; url: string }>; counterpoints: Array<{ claim: string; source: string; url: string }>; departmentNotes: Record<string, string> };
}
/** Outcome classification for a turn. */
export type TurnOutcomeType = 'risky_success' | 'risky_failure' | 'conservative_success' | 'conservative_failure';
/**
* Lifecycle hooks that a scenario provides to inject domain-specific behavior
* into the generic engine. All hooks are optional.
*/
export interface ScenarioHooks {
/** Called during between-turn progression for scenario-specific health/field changes (e.g., radiation, bone density) */
progressionHook?: (ctx: ProgressionHookContext) => void;
/** Builds department-specific prompt context lines for LLM department agents */
departmentPromptHook?: (ctx: PromptHookContext) => string[];
/** Returns the Event Director's system instructions for this scenario */
directorInstructions?: () => string;
/** Builds the Event Director's per-turn context prompt */
directorPromptHook?: (ctx: Record<string, unknown>) => string;
/** Returns location/identity/health phrasing for agent reaction prompts */
reactionContextHook?: (colonist: Agent, ctx: { time: number; turn: number }) => string;
/** Computes a timeline fingerprint classification from final simulation state */
fingerprintHook?: (finalState: SimulationState, outcomeLog: Array<{ turn: number; time: number; outcome: string }>, leader: ActorConfig, toolRegs: Record<string, string[]>, maxTurns: number) => Record<string, string>;
/** Returns a milestone event for narrative anchor turns (turn 1, final turn) */
getMilestoneEvent?: (turn: number, maxTurns: number) => MilestoneEventDef | null;
/** Returns politics deltas for political/social events, null if not applicable */
politicsHook?: (category: string, outcome: string) => Record<string, number> | null;
}
// ---------------------------------------------------------------------------
// Event definitions (scenario-driven turn events)
// ---------------------------------------------------------------------------
/** An option presented to the commander for a turn event. */
export interface EventOptionDef {
id: string;
label: string;
description: string;
isRisky: boolean;
}
/** A milestone event (fixed narrative anchor, e.g., turn 1 founding or final assessment). */
export interface MilestoneEventDef {
title: string;
description: string;
/** Full detailed narrative text for the milestone event */
crisis?: string;
options: EventOptionDef[];
riskyOptionId: string;
riskSuccessProbability: number;
category: string;
researchKeywords: string[];
relevantDepartments: string[];
turnSummary: string;
}
/** Legacy turn-based scenario (used by static SCENARIOS array and department context). */
export interface Scenario {
turn: number;
time: number;
title: string;
crisis: string;
researchKeywords: string[];
snapshotHints: Record<string, unknown>;
riskyOption: string;
riskSuccessProbability: number;
options?: EventOptionDef[];
}
// ---------------------------------------------------------------------------
// Actor config (decision-making entity per parallel run)
// ---------------------------------------------------------------------------
/**
* Configuration for a simulation actor — the swappable decision-making
* entity that runs each parallel counterfactual. Was `ActorConfig` in
* 0.7.x; renamed in 0.8.0 to match the user-facing terminology
* (`scenario.labels.actorNoun` selects the per-domain label like
* "commander" / "mayor" / "release director").
*
* The legacy `ActorConfig` name is exported below as a `@deprecated`
* type alias so 0.7.x callers compile unchanged. Drop in 1.0.
*/
export interface ActorConfig {
name: string;
archetype: string;
/**
* The organizational unit / faction / org / team this leader
* commands (e.g. "Station Alpha", "Engineering Org", "Player Faction").
* Was `colony` pre-0.5.0; renamed for domain-agnostic semantics so
* non-space scenarios (markets, game worlds, incident response) read
* naturally instead of being named after a Mars heritage concept.
*/
unit: string;
/**
* Six-axis HEXACO personality profile. Optional in v0.9: callers
* supplying `traitProfile` (e.g. ai-agent leaders) can omit this.
* The runtime requires AT LEAST ONE of `hexaco` or `traitProfile`;
* `normalizeActorConfig` throws a clear error if both are missing.
* When both are supplied, `traitProfile` wins for cue translation +
* drift; `hexaco` is preserved on the artifact for legacy display.
*/
hexaco?: HexacoProfile;
/**
* Pluggable trait profile naming a registered TraitModel and its
* per-axis values. When set, this overrides the legacy `hexaco`
* field for cue translation, drift, and prompt generation. When
* omitted, the runtime synthesizes a profile from `hexaco` with
* `modelId: 'hexaco'`.
*/
traitProfile?: TraitProfile;
instructions: string;
}
// ---------------------------------------------------------------------------
// LLM provider types
// ---------------------------------------------------------------------------
/** Supported LLM provider. */
export type LlmProvider = 'openai' | 'anthropic';
/** Model assignments for different simulation roles. */
export interface SimulationModelConfig {
commander: string;
departments: string;
judge: string;
director: string;
agentReactions?: string;
}
// ---------------------------------------------------------------------------
// ScenarioPackage (top-level)
// ---------------------------------------------------------------------------
/**
* The top-level contract for a Paracosm scenario.
* Defines everything the engine needs to run a closed-state, turn-based
* settlement simulation: world schema, departments, effects, UI metadata,
* research knowledge, policies, presets, and lifecycle hooks.
*
* @example
* ```typescript
* import type { ScenarioPackage } from 'paracosm';
* import { marsScenario } from 'paracosm';
*
* const myScenario: ScenarioPackage = { ... };
* ```
*/
export interface ScenarioPackage {
/** Unique scenario identifier (e.g., "mars-genesis", "lunar-outpost") */
id: string;
/**
* Optional permalink to the scenario JSON in the public repo (e.g.
* https://github.com/framerslab/paracosm/blob/master/scenarios/mars.json).
* Surfaced in the dashboard so users can read or fork the scenario
* source from the settings panel without leaving the app.
*/
sourceUrl?: string;
/** Semantic version of this scenario definition */
version: string;
/** Engine archetype this scenario targets */
engineArchetype: 'closed_turn_based_settlement';
labels: ScenarioLabels;
theme: ScenarioTheme;
setup: ScenarioSetupSchema;
world: ScenarioWorldSchema;
departments: DepartmentDefinition[];
metrics: MetricDefinition[];
events: EventDefinition[];
effects: EffectDefinition[];
ui: ScenarioUiDefinition;
knowledge: KnowledgeBundle;
policies: ScenarioPolicies;
presets: ScenarioPreset[];
hooks: ScenarioHooks;
}