@dsh-agentic-roleplay/state 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -133,7 +133,7 @@ characters created during play have none.
133
133
  | `locations`, `exits`, `placements` | Places (with features), the ways between them (one direction each, `open` / `locked` / `blocked`, optional travel seconds) and where things stand (a character: place, position, feature; the same table will place items). `session.planMove` / `session.move` move a character over open exits only (`InvalidMoveError` names every reason); the edit wire format can make places, change exits and move characters. |
134
134
  | `events` | What objectively happened: turn, round, text, importance (1 to 5), tags. `event_involves` lists the characters an event is about. Events are immutable: a draft until `sealed`, final afterwards (`events.seal()`); updating or removing a sealed one throws `ConflictError`. |
135
135
  | `perceptions` | What one character took in of an event, in its own terms: mode (witnessed, heard, told, inferred), content, a gist for when it fades, an accuracy label (never shown to the character), and how often it was recalled. One per character and event. |
136
- | `memories` | What a character believes or knows beyond single events: kind (belief, relationship, knowledge), text, the characters it is about, importance, the turn it formed in. |
136
+ | `memories`, `memory_evidence` | What a character believes or knows beyond single events: kind, text, subjects, importance, confidence, formation turn, and the perceptions that support or contradict it. |
137
137
  | `story_threads` | Things not settled yet: promises, mysteries, goals; open or resolved. |
138
138
  | `summaries` | The account of the story for the conversation's head: digests of recent turns and chapters of older ones, each with the turns it covers. |
139
139
  | `recall_items`, `recall_fts`, `recall_vocab`, `recall_vec` | The search index: one row per perception, memory and event, indexed by words (FTS5) and, once vectors are stored, by meaning (sqlite-vec, cosine, partitioned by character). `store.recallIndex` lists the texts without a vector (`pending`), stores vectors (`store`, which fixes the model and dimensions of the session's vectors) and searches (`lexical`, `vector`). Vector support is optional: without the extension everything but `vector` works. |
package/lib/index.d.ts CHANGED
@@ -367,6 +367,11 @@ interface LocationDefinition {
367
367
  interface RoutineWindow {
368
368
  /** The days of the week it applies on, 0 for Sunday; every day when empty. A window past midnight belongs to the day it starts on. */
369
369
  days: number[];
370
+ /**
371
+ * Other days it applies on or does not (`dec`, `12-24`, `season:winter`, `nth:mon:1`, `holiday:<id>`, a `!` before one for a day it does not apply
372
+ * on): it applies on a day that is among `days` and that these allow. Every day when empty or left out.
373
+ */
374
+ on?: string[];
370
375
  /** The minute of the day it starts, 0 to 1439. */
371
376
  start: number;
372
377
  /** The minute it ends (exclusive); before `start` it ends the next day. Equal to `start` is not a window. */
@@ -380,6 +385,7 @@ interface RoutineWindow {
380
385
  interruptible: boolean;
381
386
  }
382
387
  interface StoredRoutineWindow extends RoutineWindow {
388
+ on: string[];
383
389
  id: number;
384
390
  characterId: CharacterId;
385
391
  }
@@ -387,6 +393,8 @@ interface StoredRoutineWindow extends RoutineWindow {
387
393
  interface RoutineDefinition {
388
394
  /** Three-letter days (`mon` to `sun`); every day when left out. */
389
395
  days: string[];
396
+ /** Other days it applies on or does not, as for {@link RoutineWindow.on}. */
397
+ on?: string[];
390
398
  /** `HH:MM`. */
391
399
  from: string;
392
400
  to: string;
@@ -714,6 +722,13 @@ declare const ACCURACIES: readonly ["accurate", "partial", "mistaken"];
714
722
  type Accuracy = (typeof ACCURACIES)[number];
715
723
  declare const MEMORY_KINDS: readonly ["belief", "relationship", "knowledge"];
716
724
  type MemoryKind = (typeof MEMORY_KINDS)[number];
725
+ /** How sure a character is of what it believes, from least to most. */
726
+ declare const MEMORY_CONFIDENCES: readonly ["doubtful", "likely", "sure"];
727
+ type MemoryConfidence = (typeof MEMORY_CONFIDENCES)[number];
728
+ declare const DEFAULT_CONFIDENCE: MemoryConfidence;
729
+ /** Whether a perception speaks for a belief or against it. */
730
+ declare const EVIDENCE_RELATIONS: readonly ["supports", "contradicts"];
731
+ type EvidenceRelation = (typeof EVIDENCE_RELATIONS)[number];
717
732
  declare const THREAD_STATUSES: readonly ["open", "resolved"];
718
733
  type ThreadStatus = (typeof THREAD_STATUSES)[number];
719
734
  /** A digest covers a stretch of recent turns closely; a chapter covers older turns briefly. */
@@ -808,17 +823,30 @@ interface CharacterMemory {
808
823
  /** The characters it is about. */
809
824
  about: CharacterId[];
810
825
  importance: number;
826
+ /** How sure the character is of it. */
827
+ confidence: MemoryConfidence;
811
828
  /** The turn it was formed in. */
812
829
  turn: number;
813
830
  recalls: number;
814
831
  lastRecalledTurn?: number;
815
832
  createdAt: string;
816
833
  }
817
- type NewCharacterMemory = Omit<CharacterMemory, 'id' | 'createdAt' | 'recalls' | 'lastRecalledTurn'>;
834
+ type NewCharacterMemory = Omit<CharacterMemory, 'id' | 'createdAt' | 'recalls' | 'lastRecalledTurn' | 'confidence'> & {
835
+ confidence?: MemoryConfidence;
836
+ };
818
837
  interface CharacterMemoryPatch {
819
838
  text?: string;
820
839
  about?: CharacterId[];
821
840
  importance?: number;
841
+ confidence?: MemoryConfidence;
842
+ }
843
+ /** What a character took in that a belief rests on, or that speaks against it. */
844
+ interface MemoryEvidence {
845
+ memoryId: MemoryId;
846
+ perceptionId: PerceptionId;
847
+ relation: EvidenceRelation;
848
+ /** The turn the link was made. */
849
+ turn: number;
822
850
  }
823
851
  /** Something in the story that is not settled yet: a promise, a mystery, a goal. */
824
852
  interface StoryThread {
@@ -1012,7 +1040,7 @@ type Comparison = (typeof COMPARISONS)[number];
1012
1040
  * the story's zone: `YYYY-MM-DDTHH:MM`, and `HH:MM` for a time of day.
1013
1041
  */
1014
1042
  type TriggerCondition =
1015
- /** True from `from` on, until `to`; or while the time of day is in `window` (past midnight when it ends before it starts), on `days` (`mon` to `sun`) when given. */
1043
+ /** True from `from` on, until `to`; or while the time of day is in `window` (past midnight when it ends before it starts), on `days` (`mon` to `sun`) when given and on the days `on` allows (months, dates, seasons, holidays of the world's calendar). */
1016
1044
  {
1017
1045
  type: 'time';
1018
1046
  from?: string;
@@ -1022,6 +1050,7 @@ type TriggerCondition =
1022
1050
  to: string;
1023
1051
  };
1024
1052
  days?: string[];
1053
+ on?: string[];
1025
1054
  } |
1026
1055
  /** A character is in a place, at a feature of it when given. */
1027
1056
  {
@@ -1088,6 +1117,8 @@ interface TriggerAnnouncement {
1088
1117
  /** When it is to happen, a local time, as told with the announcement; the time the condition waits for when it is a plain one, if left out. */
1089
1118
  at?: string;
1090
1119
  }
1120
+ /** In a cue, the key of the character it is said to: in a `while` condition and in the words of the cue. */
1121
+ declare const SELF = "@self";
1091
1122
  /** What happens when a trigger fires. */
1092
1123
  type TriggerEffect =
1093
1124
  /** A checked change of the story's records, in the format of an edit (events, variable changes, exit and item changes, moves, goals, engagements). */
@@ -1095,16 +1126,22 @@ type TriggerEffect =
1095
1126
  type: 'edit';
1096
1127
  edit: Record<string, unknown>;
1097
1128
  } |
1098
- /** Something the game master is told to weave into the story, until it says it did or a few turns pass. */
1129
+ /**
1130
+ * Something the game master is told to weave into the story, until it says it did or a few turns pass. It is written when it is told, not when
1131
+ * the trigger fired: `text` may name things the story has by `{kind:key}` and so is said as the story stands then (see `TEMPLATE_KINDS`), and
1132
+ * `while` is a condition that must still hold then, or the beat is withdrawn instead.
1133
+ */
1099
1134
  {
1100
1135
  type: 'beat';
1101
1136
  text: string;
1137
+ while?: TriggerCondition;
1102
1138
  } |
1103
- /** Something the audience notices, said to each of them the next time they act. */
1139
+ /** Something the audience notices, said to each of them the next time they act; written, and withdrawn, as a beat is, for each of them (`SELF` is the one it is said to). */
1104
1140
  {
1105
1141
  type: 'cue';
1106
1142
  audience: TriggerAudience;
1107
1143
  text: string;
1144
+ while?: TriggerCondition;
1108
1145
  };
1109
1146
  declare const TRIGGER_STATUSES: readonly ["dormant", "fired", "failed", "expired"];
1110
1147
  type TriggerStatus = (typeof TRIGGER_STATUSES)[number];
@@ -1248,6 +1285,24 @@ interface PlotProgress {
1248
1285
  lastNudgeAt?: number;
1249
1286
  }
1250
1287
  //#endregion
1288
+ //#region ../dsh-roleplay-model/src/messages.d.ts
1289
+ /** The languages the texts a model reads are written in. English is the source: a text is its own key. */
1290
+ declare const LANGUAGES: readonly ["en", "zh"];
1291
+ type Language = (typeof LANGUAGES)[number];
1292
+ /** The language a setting such as `zh-CN` or `en` stands for; English when it is none that is known. */
1293
+ declare function languageOf(code: string | undefined): Language;
1294
+ type MessageValues = Readonly<Record<string, string | number>>;
1295
+ /** Says a text in the language of the story: `tr('{name} is in {place}.', { name, place })`. */
1296
+ type Translate = (text: string, values?: MessageValues) => string;
1297
+ /**
1298
+ * The texts the engine builds for a model (briefs, reports, refusals) in a language. The text written in the code is the English one and the key of
1299
+ * the others; a text a language lacks is told in English, and a test keeps that from happening.
1300
+ */
1301
+ declare function translator(language: Language): Translate;
1302
+ /** The texts with a translation, for the test that every text has one. */
1303
+ declare const translated: (language: Exclude<Language, "en">) => readonly string[];
1304
+ declare const translation: (language: Exclude<Language, "en">, text: string) => string | undefined;
1305
+ //#endregion
1251
1306
  //#region src/clock.d.ts
1252
1307
  type Clock = () => Date;
1253
1308
  declare const systemClock: Clock;
@@ -1474,6 +1529,17 @@ interface MemoryRepository {
1474
1529
  /** Count a memory as recalled in `turn`. */
1475
1530
  touch(ids: readonly MemoryId[], turn: number): void;
1476
1531
  remove(id: MemoryId): boolean;
1532
+ /** Record that a perception of the character's speaks for a belief or against it; one link per pair, the later replaces the earlier. @throws {NotFoundError} */
1533
+ addEvidence(memoryId: MemoryId, perceptionId: PerceptionId, relation: EvidenceRelation, turn: number): void;
1534
+ evidenceOf(memoryId: MemoryId): MemoryEvidence[];
1535
+ /**
1536
+ * What a character's beliefs rest on: for each perception that some belief of the character cites, the beliefs that do (it is folded into them),
1537
+ * and the beliefs something it took in speaks against (disputed).
1538
+ */
1539
+ evidenceIndex(characterId: CharacterId): {
1540
+ folded: Map<PerceptionId, MemoryId[]>;
1541
+ disputed: Set<MemoryId>;
1542
+ };
1477
1543
  }
1478
1544
  interface ThreadRepository {
1479
1545
  open(text: string, turn: number): StoryThread;
@@ -1991,6 +2057,8 @@ interface RecordsTarget {
1991
2057
  routines: RoutineRepository;
1992
2058
  engagements: EngagementRepository;
1993
2059
  triggers: TriggerRepository;
2060
+ /** What the story keeps about itself; the calendar of its world is read from here. */
2061
+ metadata: Pick<MetadataRepository, 'getValue'>;
1994
2062
  transaction<T>(fn: () => T): T;
1995
2063
  }
1996
2064
  interface PerceivedBy {
@@ -2241,12 +2309,20 @@ interface NewBelief {
2241
2309
  text: string;
2242
2310
  about?: string[];
2243
2311
  importance: number;
2312
+ /** How sure the character is; likely when not said. */
2313
+ confidence?: MemoryConfidence;
2314
+ /** The numbers of perceptions of the character's own that it rests on, and that speak against it. */
2315
+ evidenceFor?: number[];
2316
+ evidenceAgainst?: number[];
2244
2317
  }
2245
2318
  interface BeliefEdit {
2246
2319
  id: number;
2247
2320
  text?: string;
2248
2321
  about?: string[];
2249
2322
  importance?: number;
2323
+ confidence?: MemoryConfidence;
2324
+ evidenceFor?: number[];
2325
+ evidenceAgainst?: number[];
2250
2326
  }
2251
2327
  /**
2252
2328
  * A change to the story's records, applied together or not at all: the unit in which the
@@ -2301,6 +2377,8 @@ interface EngagementEditSpec {
2301
2377
  interface RoutineWindowSpec {
2302
2378
  /** `mon` to `sun`; every day when left out. */
2303
2379
  days?: string[];
2380
+ /** Other days it applies on or not: `dec`, `12-24`, `season:winter`, `nth:mon:1`, `holiday:<id>`, `!` before one for a day it does not apply on. */
2381
+ on?: string[];
2304
2382
  /** `HH:MM`. */
2305
2383
  from: string;
2306
2384
  to: string;
@@ -2389,12 +2467,12 @@ declare function parseTriggerDefinition(value: unknown, path: string, checkEdit:
2389
2467
  } | {
2390
2468
  problems: string[];
2391
2469
  };
2392
- type Reading = Pick<RecordsTarget, 'characters' | 'locations' | 'items' | 'variables' | 'triggers'>;
2470
+ type Reading$1 = Pick<RecordsTarget, 'characters' | 'locations' | 'items' | 'variables' | 'triggers' | 'metadata'>;
2393
2471
  /**
2394
2472
  * What in a trigger names something the story does not have: a character, place, item or variable in a condition, the characters of a cue,
2395
2473
  * a trigger it waits for. (What an edit effect touches is checked when it is applied.)
2396
2474
  */
2397
- declare function triggerReferenceProblems(target: Reading, definition: TriggerDefinition, otherKeys?: Iterable<string>): string[];
2475
+ declare function triggerReferenceProblems(target: Reading$1, definition: TriggerDefinition, otherKeys?: Iterable<string>): string[];
2398
2476
  interface TriggerClock {
2399
2477
  now: number;
2400
2478
  zone: string;
@@ -2461,6 +2539,30 @@ declare function lapseNotes(target: RecordsTarget, turn: number, kept: {
2461
2539
  cues: number;
2462
2540
  }): TriggerNote[];
2463
2541
  //#endregion
2542
+ //#region src/records/deferred.d.ts
2543
+ type Reading = RecordsTarget;
2544
+ /** The words cannot be written as the story stands: something they name is not there. */
2545
+ declare class UnwritableError extends Error {}
2546
+ /** Words as the story stands now. @throws {UnwritableError} when something they name is not there. */
2547
+ declare function renderWords(target: Reading, text: string, clock: TriggerClock, self?: string): string;
2548
+ interface Delivery {
2549
+ /** What is to be told now, in words as the story stands. */
2550
+ shown: {
2551
+ note: TriggerNote;
2552
+ text: string;
2553
+ }[];
2554
+ /** What is not to be told, and why: the beat or cue no longer applies, or cannot be written. */
2555
+ withdrawn: {
2556
+ note: TriggerNote;
2557
+ reason: string;
2558
+ }[];
2559
+ }
2560
+ /**
2561
+ * Decides, at the moment notes are about to be told, what is still to be told and in what words. A note whose effect says something must
2562
+ * still hold and does not hold any more is withdrawn; so is one whose words name something that is not there. Nothing is changed.
2563
+ */
2564
+ declare function deliverNotes(target: Reading, notes: readonly TriggerNote[], clock: TriggerClock): Delivery;
2565
+ //#endregion
2464
2566
  //#region src/records/movement.d.ts
2465
2567
  interface MoveContext {
2466
2568
  locations: Pick<LocationRepository, 'get' | 'allExits'>;
@@ -2512,6 +2614,11 @@ interface MemoryPolicy {
2512
2614
  * included) to 1 (only what adds something new): maximal marginal relevance over the pool. 0 or absent: none.
2513
2615
  */
2514
2616
  diversity?: number;
2617
+ /**
2618
+ * How long what a character took in lasts once a belief rests on it, as a share of how long it would last: below 1 it fades sooner, the
2619
+ * belief having taken over, and it is not told again when that belief is told. 1 or absent: no change.
2620
+ */
2621
+ foldedFade?: number;
2515
2622
  }
2516
2623
  declare const DEFAULT_MEMORY_POLICY: MemoryPolicy;
2517
2624
  /** How much of a memory is left: what the character is told of it. */
@@ -2531,6 +2638,10 @@ interface Recalled {
2531
2638
  };
2532
2639
  /** It did not match the moment itself: it came to mind with something that did ({@link MemoryPolicy.associate}). */
2533
2640
  linked?: true;
2641
+ /** For what the character believes: how sure it is. */
2642
+ confidence?: MemoryConfidence;
2643
+ /** For what the character believes: something it took in since speaks against it. */
2644
+ disputed?: true;
2534
2645
  /** Why it came back, when the query asked to be told ({@link RecallQuery.explain}). */
2535
2646
  why?: RecallWhy;
2536
2647
  }
@@ -2580,7 +2691,7 @@ interface RecallQuery {
2580
2691
  /** What recall reads: the events a character took in and what it believes. */
2581
2692
  interface RecallSource {
2582
2693
  events: Pick<EventRepository, 'perceivedBy'>;
2583
- memories: Pick<MemoryRepository, 'list'>;
2694
+ memories: Pick<MemoryRepository, 'list'> & Partial<Pick<MemoryRepository, 'evidenceIndex'>>;
2584
2695
  clock: Pick<ClockRepository, 'get' | 'log'>;
2585
2696
  /** Optional for lightweight callers; a session supplies it so socially charged people are stronger cues. */
2586
2697
  relationships?: Pick<RelationshipRepository, 'from'>;
@@ -2623,6 +2734,8 @@ interface Candidate {
2623
2734
  recalls: number;
2624
2735
  seed: number;
2625
2736
  durability: number;
2737
+ /** For something the character took in that beliefs rest on: those beliefs. */
2738
+ covered?: number[];
2626
2739
  }
2627
2740
  declare function overlap(cues: ReadonlySet<string>, text: string, tags: readonly string[]): number;
2628
2741
  /** One thing a character could be reminded of, with the text to match it against the moment. */
@@ -2646,7 +2759,9 @@ interface RecallEvidence {
2646
2759
  rerank?: ReadonlyMap<string, number>;
2647
2760
  }
2648
2761
  /** Everything the character could be reminded of, for a caller that ranks by meaning (an embedding, a reranker) before asking for the recall. */
2649
- declare function recallCandidates(source: RecallSource, query: Pick<RecallQuery, 'characterId' | 'characters' | 'situation' | 'turn' | 'locationId' | 'about'>): RecallCandidate[];
2762
+ declare function recallCandidates(source: RecallSource, query: Pick<RecallQuery, 'characterId' | 'characters' | 'situation' | 'turn' | 'locationId' | 'about'> & {
2763
+ policy?: MemoryPolicy;
2764
+ }): RecallCandidate[];
2650
2765
  /** Fuse scores from 0 to 1 into one, per key: the weighted average over the searches that ran (those with any score above 0). */
2651
2766
  declare function fuseScores(searches: readonly {
2652
2767
  weight: number;
@@ -2820,6 +2935,9 @@ interface RecordsView {
2820
2935
  text: string;
2821
2936
  about: string[];
2822
2937
  importance: number;
2938
+ confidence: string;
2939
+ evidence_for: number[];
2940
+ evidence_against: number[];
2823
2941
  turn: number;
2824
2942
  }[];
2825
2943
  open_threads: {
@@ -3008,6 +3126,8 @@ interface SessionStore {
3008
3126
  beats: number;
3009
3127
  cues: number;
3010
3128
  }): TriggerNote[];
3129
+ /** Which of these notes are still to be told, and in what words as the story stands now; the others are withdrawn, with the reason. Nothing is changed. */
3130
+ deliverNotes(notes: readonly TriggerNote[], clock: TriggerClock): Delivery;
3011
3131
  /** Write a consistent copy of the whole database to `path`, which must not exist. */
3012
3132
  snapshotTo(path: string): void;
3013
3133
  close(): void;
@@ -3216,6 +3336,95 @@ declare function createCharacterTools(link: () => AgentLink, characterId: Charac
3216
3336
  /** Why a value is not one the variable can have, or nothing when it is. */
3217
3337
  declare function valueIssue(def: Pick<VariableDefinition, 'key' | 'kind' | 'min' | 'max' | 'integer' | 'options'>, value: unknown): string | undefined;
3218
3338
  //#endregion
3339
+ //#region src/records/calendar.d.ts
3340
+ /**
3341
+ * Which days a thing applies on, beyond the days of the week: whole months, a date every year or once, a stretch of dates, the day of the month,
3342
+ * the first or last Monday of a month, a season, and the holidays a world names. A day is told by tokens (`dec`, `12-24`, `1912-09-21..1912-09-22`,
3343
+ * `dom:1`, `nth:mon:1`, `season:winter`, `holiday:founders-day`, `fri`); a token with `!` before it is a day it does not apply on. A list holds on a
3344
+ * day when it names no day to apply on or one of them is today, and none of the days to leave out is.
3345
+ */
3346
+ declare const MONTH_NAMES: readonly ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
3347
+ declare const SEASONS: readonly ["spring", "summer", "autumn", "winter"];
3348
+ type Season = (typeof SEASONS)[number];
3349
+ type Hemisphere = 'north' | 'south';
3350
+ /** A day by the wall clock of the story: the month is 1 to 12 and the weekday 0 (Sunday) to 6. */
3351
+ interface CalendarDay {
3352
+ year: number;
3353
+ month: number;
3354
+ day: number;
3355
+ weekday: number;
3356
+ }
3357
+ interface Holiday {
3358
+ id: string;
3359
+ name: string;
3360
+ /** The days it falls on, as tokens other than `holiday:`. */
3361
+ on: string[];
3362
+ }
3363
+ interface Calendar {
3364
+ hemisphere: Hemisphere;
3365
+ holidays: Holiday[];
3366
+ }
3367
+ declare const NO_CALENDAR: Calendar;
3368
+ type Parsed = {
3369
+ kind: 'weekday';
3370
+ weekday: number;
3371
+ } | {
3372
+ kind: 'month';
3373
+ month: number;
3374
+ } | {
3375
+ kind: 'date';
3376
+ year?: number;
3377
+ month: number;
3378
+ day: number;
3379
+ } | {
3380
+ kind: 'span';
3381
+ from: {
3382
+ year?: number;
3383
+ month: number;
3384
+ day: number;
3385
+ };
3386
+ to: {
3387
+ year?: number;
3388
+ month: number;
3389
+ day: number;
3390
+ };
3391
+ } | {
3392
+ kind: 'dom';
3393
+ day: number | 'last';
3394
+ } | {
3395
+ kind: 'nth';
3396
+ weekday: number;
3397
+ n: number | 'last';
3398
+ } | {
3399
+ kind: 'season';
3400
+ season: Season;
3401
+ } | {
3402
+ kind: 'holiday';
3403
+ id: string;
3404
+ };
3405
+ /** What a token says, or why it says nothing. */
3406
+ declare function parseDayToken(raw: string): {
3407
+ token: Parsed;
3408
+ negated: boolean;
3409
+ } | {
3410
+ problem: string;
3411
+ };
3412
+ /** What is wrong with a list of day tokens, each with where it is. `holidays` are those the world names, when `holiday:` may be used. */
3413
+ declare function dayTokenProblems(tokens: readonly string[], path: string, holidays?: ReadonlySet<string> | 'any'): string[];
3414
+ /** The season a day is in, by the months of its hemisphere (winter is December to February in the north, June to August in the south). */
3415
+ declare function seasonOf(day: Pick<CalendarDay, 'month'>, hemisphere?: Hemisphere): Season;
3416
+ /** Whether a list of day tokens holds on a day; tokens that say nothing sensible count as not matching. An empty list holds on every day. */
3417
+ declare function dayMatches(tokens: readonly string[], day: CalendarDay, calendar?: Calendar): boolean;
3418
+ /** The holidays that fall on a day. A holiday is told by days that are no holidays themselves, so that none can lead back to itself. */
3419
+ declare function holidaysOn(calendar: Calendar, day: CalendarDay): Holiday[];
3420
+ /** The calendar a story was started with, from its metadata; none when the world has none. */
3421
+ declare function readCalendar(metadata: {
3422
+ getValue(key: string): unknown;
3423
+ }): Calendar;
3424
+ declare const writeCalendar: (metadata: {
3425
+ setValue(key: string, value: never): void;
3426
+ }, calendar: Calendar) => void;
3427
+ //#endregion
3219
3428
  //#region src/records/agenda.d.ts
3220
3429
  /** One occurrence of a routine window: the stretch of time it holds on a particular day. */
3221
3430
  interface Occurrence {
@@ -3226,9 +3435,9 @@ interface Occurrence {
3226
3435
  /** An engagement still pending this long after it was due (or over) is overdue. */
3227
3436
  declare const ENGAGEMENT_GRACE: number;
3228
3437
  /** The window that holds at an instant (the first of the list that does), with the stretch of this occurrence of it. */
3229
- declare function occurrenceAt(windows: readonly StoredRoutineWindow[], now: number, zone: string): Occurrence | undefined;
3438
+ declare function occurrenceAt(windows: readonly StoredRoutineWindow[], now: number, zone: string, calendar?: Calendar): Occurrence | undefined;
3230
3439
  /** The window that starts next after an instant, within `horizon`. */
3231
- declare function nextOccurrence(windows: readonly StoredRoutineWindow[], now: number, zone: string, horizon: number): Occurrence | undefined;
3440
+ declare function nextOccurrence(windows: readonly StoredRoutineWindow[], now: number, zone: string, horizon: number, calendar?: Calendar): Occurrence | undefined;
3232
3441
  interface RankedGoal {
3233
3442
  intent: CharacterIntent;
3234
3443
  /** The deadline as an instant, when it has one that can be read. */
@@ -3262,6 +3471,9 @@ declare function agendaAt(source: {
3262
3471
  routines: Pick<RoutineRepository, 'list'>;
3263
3472
  engagements: Pick<EngagementRepository, 'list'>;
3264
3473
  intents: Pick<IntentRepository, 'list'>;
3474
+ metadata?: {
3475
+ getValue(key: string): unknown;
3476
+ };
3265
3477
  }, characterId: CharacterId, now: number, zone: string, options?: AgendaOptions): Agenda;
3266
3478
  //#endregion
3267
3479
  //#region src/sqlite/agenda-repositories.d.ts
@@ -3307,16 +3519,16 @@ declare function zonedInstant(fields: {
3307
3519
  * @throws {RangeError} when it is not a date and time.
3308
3520
  */
3309
3521
  declare function parseInstant(text: string, zone: string): number;
3310
- /** `Tuesday 4 October 1912, 21:40`. */
3311
- declare function describeInstant(instant: number, zone: string): string;
3522
+ /** `Tuesday 4 October 1912, 21:40`, or `1912年10月4日 星期二 21:40`. */
3523
+ declare function describeInstant(instant: number, zone: string, language?: 'en' | 'zh'): string;
3312
3524
  /** `1912-10-04T21:40:00` as the wall clock of a zone reads, the form a file or a person can write back. */
3313
3525
  declare function localIso(instant: number, zone: string): string;
3314
3526
  declare const DAY_PARTS: readonly ["night", "morning", "afternoon", "evening"];
3315
3527
  type DayPart = (typeof DAY_PARTS)[number];
3316
3528
  /** Night is from 22:00 to 05:00, morning to 12:00, afternoon to 17:00, evening after. */
3317
3529
  declare function dayPart(minuteOfDay: number): DayPart;
3318
- /** In words and rounded to what matters: `45 seconds`, `3 hours 12 minutes`, `2 days 3 hours`. */
3319
- declare function describeDuration(milliseconds: number): string;
3530
+ /** In words and rounded to what matters: `45 seconds`, `3 hours 12 minutes`, `2 days 3 hours`; or `45秒`, `3小时12分钟`, `2天3小时`. */
3531
+ declare function describeDuration(milliseconds: number, language?: 'en' | 'zh'): string;
3320
3532
  /** The minute of the day for `HH:MM` (24-hour), or nothing when it is not one. */
3321
3533
  declare function parseTimeOfDay(text: string): number | undefined;
3322
3534
  /**
@@ -3353,6 +3565,60 @@ declare function addLocalDays(instant: number, zone: string, days: number): {
3353
3565
  weekday: number;
3354
3566
  };
3355
3567
  //#endregion
3568
+ //#region src/records/template.d.ts
3569
+ /**
3570
+ * What the words of a cue or a beat may name by `{kind:key}`, filled in from the story when they are told. The key is how the world's files
3571
+ * name the thing (`@self` in a cue is the character it is said to), and a name follows the story: a renamed character is renamed in the words.
3572
+ */
3573
+ declare const TEMPLATE_KINDS: {
3574
+ /** The name of a character. */
3575
+ readonly character: {
3576
+ readonly args: 1;
3577
+ readonly about: "a character";
3578
+ };
3579
+ /** The name of a place. */
3580
+ readonly place: {
3581
+ readonly args: 1;
3582
+ readonly about: "a place";
3583
+ };
3584
+ /** The name of an item. */
3585
+ readonly item: {
3586
+ readonly args: 1;
3587
+ readonly about: "an item";
3588
+ };
3589
+ /** The name of the place a character is in now. */
3590
+ readonly where: {
3591
+ readonly args: 1;
3592
+ readonly about: "a character";
3593
+ };
3594
+ /** Who holds an item now, or the place it lies in. */
3595
+ readonly holder: {
3596
+ readonly args: 1;
3597
+ readonly about: "an item";
3598
+ };
3599
+ /** What a variable is now, in words: `{value:key}` for a world variable, `{value:key:subject}` for the character, item or place it is about. */
3600
+ readonly value: {
3601
+ readonly args: 2;
3602
+ readonly about: "a variable";
3603
+ };
3604
+ /** The time of day in the story, as `19:30`. */
3605
+ readonly time: {
3606
+ readonly args: 0;
3607
+ readonly about: "";
3608
+ };
3609
+ };
3610
+ type TemplateKind = keyof typeof TEMPLATE_KINDS;
3611
+ interface Placeholder {
3612
+ raw: string;
3613
+ kind: TemplateKind;
3614
+ args: string[];
3615
+ }
3616
+ /** The placeholders in some words, and what is wrong with any that is not one. Anything that does not look like `{word}` or `{word:key}` is plain text. */
3617
+ declare function placeholdersOf(text: string): {
3618
+ found: Placeholder[];
3619
+ problems: string[];
3620
+ };
3621
+ //#endregion
3356
3622
  //#region src/records/lint.d.ts
3357
3623
  type LintSeverity = 'error' | 'warning' | 'info';
3358
3624
  interface LintFinding {
@@ -3373,5 +3639,5 @@ type LintTarget = Pick<RecordsTarget, 'characters' | 'locations' | 'placements'
3373
3639
  */
3374
3640
  declare function lintWorld(target: LintTarget): LintFinding[];
3375
3641
  //#endregion
3376
- export { ACCURACIES, Accuracy, type Agenda, type AgendaEngagement, type AgendaOptions, type AgentLink, type AgentResolver, type Announcement, type BeliefEdit, CHARACTER_CONTROLS, CHARACTER_KINDS, CHARACTER_ROLES, CHARACTER_TIERS, CLOCK_MODES, COMPARISONS, CONSOLIDATION_KINDS, CONTAINER_STATES, Character, CharacterControl, CharacterDefinition, CharacterFilter, CharacterId, CharacterIntent, CharacterKind, CharacterMemory, CharacterMemoryPatch, type CharacterMove, CharacterPatch, type CharacterRepository, CharacterRole, CharacterSpeech, CharacterStart, CharacterState, CharacterStatePatch, type CharacterStateRepository, CharacterTier, type Clarity, type Clock, ClockMode, ClockState, Comparison, Config, ConflictError, ConsolidationItem, ConsolidationItemId, ConsolidationKind, type ConsolidationRepository, ContainerSpec, ContainerState, CorruptDataError, DAY, DAY_PARTS, DEFAULT_MEMORY_POLICY, DEFAULT_SLOTS, type DayPart, EMOTION_VARIABLES, ENGAGEMENT_GRACE, ENGAGEMENT_STATUSES, EXIT_STATES, type EditChecker, type EditResult, EmbeddingIndexInfo, EmotionStart, EmotionVector, Engagement, EngagementFilter, EngagementId, EngagementPatch, EngagementStatus, EntityKnowledge, type EventEdit, EventId, type EventRepository, Exit, type ExitChange, ExitDefinition, ExitId, ExitOpener, ExitPatch, ExitState, Faction, FactionDefinition, FactionId, FactionIntent, type FactionIntentRepository, FactionMembership, FactionMembershipDefinition, type FactionMembershipRepository, FactionPatch, FactionRelationship, FactionRelationshipDefinition, type FactionRelationshipRepository, type FactionRepository, FactionState, FactionStatePatch, type FactionStateRepository, type FiredTrigger, HOUR, Holder, Holding, IMPORTANCE_MAX, IMPORTANCE_MIN, INTENT_HORIZONS, INTENT_STATUSES, INTENT_TYPES, ITEM_ACTIONS, Intent, IntentFilter, IntentHorizon, IntentId, IntentPatch, type IntentRepository, IntentStatus, IntentType, InvalidEditError, InvalidMoveError, InvalidValueError, Item, type ItemAction, type ItemChange, type ItemChangeSpec, type ItemContext, ItemDefinition, type ItemEditSpec, type ItemEffect, ItemId, ItemPatch, type ItemPlan, type ItemRepository, JsonValue, KNOWLEDGE_KINDS, KnowledgeDefinition, KnowledgeKind, type KnowledgeRepository, type KnownMoveContext, LORE_KINDS, LORE_SUBJECT_KINDS, type LintFinding, type LintSeverity, type LintTarget, type LocalTime, Location, LocationDefinition, LocationFeature, LocationId, LocationPatch, type LocationRepository, Lore, LoreDefinition, LoreId, LoreKind, LorePatch, LoreSubject, LoreSubjectDefinition, LoreSubjectKind, MAX_LOCATION_FEATURES, MAX_ROUTINE_WINDOWS, MAX_SHOWN, MAX_TRIGGERS, MAX_VARIABLES, MEMBERSHIP_STATUSES, MEMORY_KINDS, MIGRATION_BACKUP_FOLDER, MINUTE, MembershipPatch, MembershipStatus, MemoryId, MemoryKind, type MemoryPolicy, type MemoryRepository, type MetadataRepository, Move, type MoveContext, MovePlan, type NewBelief, NewCharacter, NewCharacterMemory, type NewCharacterSpec, NewCharacterState, NewEngagement, type NewEvent, NewExit, type NewExitBetween, type NewExit$1 as NewExitEdit, NewFaction, NewFactionState, NewItem, type NewItemSpec, NewLocation, NewLore, NewPerception, type NewPlace, NewPlacement, NewRelationship, NewSession, NewStoryEvent, NewSummary, NewTriggerNote, NotFoundError, type Occurrence, type OpenOptions, PERCEPTION_MODES, PLACEABLE_KINDS, PLOT_NUDGE_MODES, PLOT_STATUSES, PendingCommit, type PendingCommitRepository, PendingEmbedding, type PerceivedBy, PerceivedEvent, Perception, type PerceptionAddition, type PerceptionEdit, PerceptionId, PerceptionMode, PerceptionPatch, type PlaceEdit, PlaceableKind, Placement, type PlacementRepository, PlotDefinition, PlotDevelopment, PlotNudgeMode, PlotProgress, PlotStatus, RECALL_ITEM_KINDS, type RankedGoal, type RecallCandidate, type RecallEvidence, RecallHit, type RecallIndexRepository, RecallItemKind, type RecallPool, type RecallQuery, type RecallSearch, type RecallSource, type RecallWhy, type Recalled, type RecordsEdit, type RecordsScope, type RecordsTarget, type RecordsView, Relationship, RelationshipDefinition, RelationshipId, RelationshipPatch, type RelationshipRepository, type RelationshipRetraction, type RelationshipSet, RoleplayState, RoutineDefinition, RoutineWindow, type RunResult, LATEST_VERSION as SCHEMA_VERSION, SECOND, SESSION_DATABASE_FILE, SLOT_ID, SUMMARY_LEVELS, SchemaError, type SemanticRanker, type Session, type SessionInit, type SessionListing, SessionMetadata, type SessionStore, type ShownVariable, Slot, type SlotRepository, SocialSubjectKind, type SqlDatabase, type SqlDriver, type SqlValue, StateError, type StatePatch, type StoreOptions, StoredRoutineWindow, StoredVariable, StoryEvent, StoryEventFilter, StoryEventPatch, StoryThread, Summary, SummaryId, SummaryLevel, type SummaryRepository, THREAD_STATUSES, TIME_CHANGE_KINDS, TRIGGER_NOTE_KINDS, TRIGGER_STATUSES, ThreadId, type ThreadRepository, ThreadStatus, TimeChange, TimeChangeFilter, TimeChangeKind, Trigger, TriggerAnnouncement, TriggerAudience, type TriggerClock, TriggerCondition, TriggerDefinition, TriggerEffect, TriggerId, TriggerNote, TriggerNoteKind, type TriggerRun, type TriggerRunOptions, TriggerStatus, VARIABLE_KEY, VARIABLE_KINDS, VARIABLE_SUBJECTS, VARIABLE_VISIBILITIES, VISUAL_SUBJECT_KINDS, type VariableAudience, VariableBand, type VariableChangeSpec, type VariableContext, VariableDefinition, VariableDefinitionInput, type VariableEffect, VariableKind, type VariablePlan, VariableSubject, VariableValue, VariableVisibility, type VectorSearch, type VectorSupport, VisualIdentity, VisualIdentityInput, VisualIdentityPatch, type VisualIdentityRepository, VisualSubjectKind, WEEKDAY_NAMES, WorldReference, addLocalDays, agendaAt, announcements, apply, applyItemPlan, applyRecordsEdit, audienceIds, catchUpPlan, changeItem, changeVariable, characterKey, clarityAt, clockTime, conditionHolds, createCharacterTools, createSession, createSessionStore, createTools, dayPart, deleteSession, denseScore, describeDuration, describeHolder, describeInstant, describeValue, finishRecall, fuseScores, inAudience, inWindow, isSessionId, isTimeZone, itemKey, jitter, judgedStatements, lapseNotes, lintWorld, listSessions, localIso, localTime, locationKey, mentioned, migrationBackupPath, moveCharacter, name, nextOccurrence, nextTimeOfDay, nodeSqliteDriver, occurrenceAt, openSession, openSessionStore, overlap, parseInstant, parseRecordsEdit, parseTimeOfDay, parseTriggerDefinition, planItemChange, planKnownMove, planMove, planVariableChange, poolCandidates, rankGoals, readRecords, readTriggerDefinition, recall, recallCandidates, recallPool, recordsEditSchema, retention, runTriggers, seededRoll, sessionDatabase, sessionFolder, shownVariables, subjectOf, systemClock, systemTimeZone, tokens, triggerReferenceProblems, valueIssue, zonedInstant };
3642
+ export { ACCURACIES, Accuracy, type Agenda, type AgendaEngagement, type AgendaOptions, type AgentLink, type AgentResolver, type Announcement, type BeliefEdit, CHARACTER_CONTROLS, CHARACTER_KINDS, CHARACTER_ROLES, CHARACTER_TIERS, CLOCK_MODES, COMPARISONS, CONSOLIDATION_KINDS, CONTAINER_STATES, type Calendar, type CalendarDay, Character, CharacterControl, CharacterDefinition, CharacterFilter, CharacterId, CharacterIntent, CharacterKind, CharacterMemory, CharacterMemoryPatch, type CharacterMove, CharacterPatch, type CharacterRepository, CharacterRole, CharacterSpeech, CharacterStart, CharacterState, CharacterStatePatch, type CharacterStateRepository, CharacterTier, type Clarity, type Clock, ClockMode, ClockState, Comparison, Config, ConflictError, ConsolidationItem, ConsolidationItemId, ConsolidationKind, type ConsolidationRepository, ContainerSpec, ContainerState, CorruptDataError, DAY, DAY_PARTS, DEFAULT_CONFIDENCE, DEFAULT_MEMORY_POLICY, DEFAULT_SLOTS, type DayPart, type Delivery, EMOTION_VARIABLES, ENGAGEMENT_GRACE, ENGAGEMENT_STATUSES, EVIDENCE_RELATIONS, EXIT_STATES, type EditChecker, type EditResult, EmbeddingIndexInfo, EmotionStart, EmotionVector, Engagement, EngagementFilter, EngagementId, EngagementPatch, EngagementStatus, EntityKnowledge, type EventEdit, EventId, type EventRepository, EvidenceRelation, Exit, type ExitChange, ExitDefinition, ExitId, ExitOpener, ExitPatch, ExitState, Faction, FactionDefinition, FactionId, FactionIntent, type FactionIntentRepository, FactionMembership, FactionMembershipDefinition, type FactionMembershipRepository, FactionPatch, FactionRelationship, FactionRelationshipDefinition, type FactionRelationshipRepository, type FactionRepository, FactionState, FactionStatePatch, type FactionStateRepository, type FiredTrigger, HOUR, type Hemisphere, Holder, Holding, type Holiday, IMPORTANCE_MAX, IMPORTANCE_MIN, INTENT_HORIZONS, INTENT_STATUSES, INTENT_TYPES, ITEM_ACTIONS, Intent, IntentFilter, IntentHorizon, IntentId, IntentPatch, type IntentRepository, IntentStatus, IntentType, InvalidEditError, InvalidMoveError, InvalidValueError, Item, type ItemAction, type ItemChange, type ItemChangeSpec, type ItemContext, ItemDefinition, type ItemEditSpec, type ItemEffect, ItemId, ItemPatch, type ItemPlan, type ItemRepository, JsonValue, KNOWLEDGE_KINDS, KnowledgeDefinition, KnowledgeKind, type KnowledgeRepository, type KnownMoveContext, LANGUAGES, LORE_KINDS, LORE_SUBJECT_KINDS, Language, type LintFinding, type LintSeverity, type LintTarget, type LocalTime, Location, LocationDefinition, LocationFeature, LocationId, LocationPatch, type LocationRepository, Lore, LoreDefinition, LoreId, LoreKind, LorePatch, LoreSubject, LoreSubjectDefinition, LoreSubjectKind, MAX_LOCATION_FEATURES, MAX_ROUTINE_WINDOWS, MAX_SHOWN, MAX_TRIGGERS, MAX_VARIABLES, MEMBERSHIP_STATUSES, MEMORY_CONFIDENCES, MEMORY_KINDS, MIGRATION_BACKUP_FOLDER, MINUTE, MONTH_NAMES, MembershipPatch, MembershipStatus, MemoryConfidence, MemoryEvidence, MemoryId, MemoryKind, type MemoryPolicy, type MemoryRepository, MessageValues, type MetadataRepository, Move, type MoveContext, MovePlan, NO_CALENDAR, type NewBelief, NewCharacter, NewCharacterMemory, type NewCharacterSpec, NewCharacterState, NewEngagement, type NewEvent, NewExit, type NewExitBetween, type NewExit$1 as NewExitEdit, NewFaction, NewFactionState, NewItem, type NewItemSpec, NewLocation, NewLore, NewPerception, type NewPlace, NewPlacement, NewRelationship, NewSession, NewStoryEvent, NewSummary, NewTriggerNote, NotFoundError, type Occurrence, type OpenOptions, PERCEPTION_MODES, PLACEABLE_KINDS, PLOT_NUDGE_MODES, PLOT_STATUSES, PendingCommit, type PendingCommitRepository, PendingEmbedding, type PerceivedBy, PerceivedEvent, Perception, type PerceptionAddition, type PerceptionEdit, PerceptionId, PerceptionMode, PerceptionPatch, type PlaceEdit, PlaceableKind, type Placeholder, Placement, type PlacementRepository, PlotDefinition, PlotDevelopment, PlotNudgeMode, PlotProgress, PlotStatus, RECALL_ITEM_KINDS, type RankedGoal, type RecallCandidate, type RecallEvidence, RecallHit, type RecallIndexRepository, RecallItemKind, type RecallPool, type RecallQuery, type RecallSearch, type RecallSource, type RecallWhy, type Recalled, type RecordsEdit, type RecordsScope, type RecordsTarget, type RecordsView, Relationship, RelationshipDefinition, RelationshipId, RelationshipPatch, type RelationshipRepository, type RelationshipRetraction, type RelationshipSet, RoleplayState, RoutineDefinition, RoutineWindow, type RunResult, LATEST_VERSION as SCHEMA_VERSION, SEASONS, SECOND, SELF, SESSION_DATABASE_FILE, SLOT_ID, SUMMARY_LEVELS, SchemaError, type Season, type SemanticRanker, type Session, type SessionInit, type SessionListing, SessionMetadata, type SessionStore, type ShownVariable, Slot, type SlotRepository, SocialSubjectKind, type SqlDatabase, type SqlDriver, type SqlValue, StateError, type StatePatch, type StoreOptions, StoredRoutineWindow, StoredVariable, StoryEvent, StoryEventFilter, StoryEventPatch, StoryThread, Summary, SummaryId, SummaryLevel, type SummaryRepository, TEMPLATE_KINDS, THREAD_STATUSES, TIME_CHANGE_KINDS, TRIGGER_NOTE_KINDS, TRIGGER_STATUSES, type TemplateKind, ThreadId, type ThreadRepository, ThreadStatus, TimeChange, TimeChangeFilter, TimeChangeKind, Translate, Trigger, TriggerAnnouncement, TriggerAudience, type TriggerClock, TriggerCondition, TriggerDefinition, TriggerEffect, TriggerId, TriggerNote, TriggerNoteKind, type TriggerRun, type TriggerRunOptions, TriggerStatus, UnwritableError, VARIABLE_KEY, VARIABLE_KINDS, VARIABLE_SUBJECTS, VARIABLE_VISIBILITIES, VISUAL_SUBJECT_KINDS, type VariableAudience, VariableBand, type VariableChangeSpec, type VariableContext, VariableDefinition, VariableDefinitionInput, type VariableEffect, VariableKind, type VariablePlan, VariableSubject, VariableValue, VariableVisibility, type VectorSearch, type VectorSupport, VisualIdentity, VisualIdentityInput, VisualIdentityPatch, type VisualIdentityRepository, VisualSubjectKind, WEEKDAY_NAMES, WorldReference, addLocalDays, agendaAt, announcements, apply, applyItemPlan, applyRecordsEdit, audienceIds, catchUpPlan, changeItem, changeVariable, characterKey, clarityAt, clockTime, conditionHolds, createCharacterTools, createSession, createSessionStore, createTools, dayMatches, dayPart, dayTokenProblems, deleteSession, deliverNotes, denseScore, describeDuration, describeHolder, describeInstant, describeValue, finishRecall, fuseScores, holidaysOn, inAudience, inWindow, isSessionId, isTimeZone, itemKey, jitter, judgedStatements, languageOf, lapseNotes, lintWorld, listSessions, localIso, localTime, locationKey, mentioned, migrationBackupPath, moveCharacter, name, nextOccurrence, nextTimeOfDay, nodeSqliteDriver, occurrenceAt, openSession, openSessionStore, overlap, parseDayToken, parseInstant, parseRecordsEdit, parseTimeOfDay, parseTriggerDefinition, placeholdersOf, planItemChange, planKnownMove, planMove, planVariableChange, poolCandidates, rankGoals, readCalendar, readRecords, readTriggerDefinition, recall, recallCandidates, recallPool, recordsEditSchema, renderWords, retention, runTriggers, seasonOf, seededRoll, sessionDatabase, sessionFolder, shownVariables, subjectOf, systemClock, systemTimeZone, tokens, translated, translation, translator, triggerReferenceProblems, valueIssue, writeCalendar, zonedInstant };
3377
3643
  //# sourceMappingURL=index.d.ts.map