@dsh-agentic-roleplay/state 0.3.3 → 0.3.4
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/lib/index.d.ts +15 -0
- package/lib/index.js +97 -0
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -2487,6 +2487,20 @@ interface RoutineWindowSpec {
|
|
|
2487
2487
|
position?: string;
|
|
2488
2488
|
interruptible?: boolean;
|
|
2489
2489
|
}
|
|
2490
|
+
/** One day on which a character does something other than its routine says: it takes the place of the routine's windows on that date and is dropped when the same date is set again. */
|
|
2491
|
+
interface RoutineExceptionSpec {
|
|
2492
|
+
character: string;
|
|
2493
|
+
/** The date, `YYYY-MM-DD`, in the story's time zone. */
|
|
2494
|
+
date: string;
|
|
2495
|
+
activity: string;
|
|
2496
|
+
/** `HH:MM`; the whole day when left out. */
|
|
2497
|
+
from?: string;
|
|
2498
|
+
to?: string;
|
|
2499
|
+
location?: string;
|
|
2500
|
+
feature?: string;
|
|
2501
|
+
position?: string;
|
|
2502
|
+
interruptible?: boolean;
|
|
2503
|
+
}
|
|
2490
2504
|
/** Sets the recurring day of a character, replacing what it had. */
|
|
2491
2505
|
interface RoutineSet {
|
|
2492
2506
|
character: string;
|
|
@@ -2506,6 +2520,7 @@ interface RecordsEdit {
|
|
|
2506
2520
|
engagements?: NewEngagementSpec[];
|
|
2507
2521
|
engagementEdits?: EngagementEditSpec[];
|
|
2508
2522
|
routines?: RoutineSet[];
|
|
2523
|
+
routineExceptions?: RoutineExceptionSpec[];
|
|
2509
2524
|
/** Things the world does when their conditions come true, only by the agent whose work that is. */
|
|
2510
2525
|
triggers?: TriggerDefinition[];
|
|
2511
2526
|
states?: StatePatch[];
|
package/lib/index.js
CHANGED
|
@@ -1487,6 +1487,12 @@ const MAX_PLAN_STEPS = 8;
|
|
|
1487
1487
|
const MAX_LIST_ENTRY = 240;
|
|
1488
1488
|
const present$1 = (value) => value !== void 0 && value.trim() !== "";
|
|
1489
1489
|
const list$1 = (value) => value ?? [];
|
|
1490
|
+
const FULL_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
1491
|
+
const isExceptionOn = (on, date) => on.length === 1 && on[0] === date;
|
|
1492
|
+
const ALL_DAY = {
|
|
1493
|
+
from: "00:00",
|
|
1494
|
+
to: "23:59"
|
|
1495
|
+
};
|
|
1490
1496
|
/** Checks the goals, engagements and routines of an edit, and says what they would write. Problems are added to the context's. */
|
|
1491
1497
|
function prepareAgenda(target, edit, context) {
|
|
1492
1498
|
const { idOf, placeKnown, problems } = context;
|
|
@@ -1652,6 +1658,39 @@ function prepareAgenda(target, edit, context) {
|
|
|
1652
1658
|
character,
|
|
1653
1659
|
windows
|
|
1654
1660
|
}];
|
|
1661
|
+
}),
|
|
1662
|
+
exceptions: list$1(edit.routineExceptions).flatMap((spec, index) => {
|
|
1663
|
+
const where = `routine_exceptions[${index}]`;
|
|
1664
|
+
const character = idOf(spec.character, where);
|
|
1665
|
+
if (!FULL_DATE.test(spec.date)) problems.push(`${where}.date: "${spec.date}" is not a date (YYYY-MM-DD)`);
|
|
1666
|
+
else problems.push(...dayTokenProblems([spec.date], `${where}.date`));
|
|
1667
|
+
if (!present$1(spec.activity)) problems.push(`${where}: say what the character does that day`);
|
|
1668
|
+
if (spec.from === void 0 !== (spec.to === void 0)) problems.push(`${where}: give both from and to, or neither for the whole day`);
|
|
1669
|
+
const start = parseTimeOfDay(spec.from ?? ALL_DAY.from);
|
|
1670
|
+
const end = parseTimeOfDay(spec.to ?? ALL_DAY.to);
|
|
1671
|
+
if (start === void 0) problems.push(`${where}.from: "${spec.from}" is not a time of day (HH:MM)`);
|
|
1672
|
+
if (end === void 0) problems.push(`${where}.to: "${spec.to}" is not a time of day (HH:MM)`);
|
|
1673
|
+
if (start !== void 0 && start === end) problems.push(`${where}: it starts and ends at the same time`);
|
|
1674
|
+
if (spec.location !== void 0) {
|
|
1675
|
+
placeKnown(spec.location, `${where}.location`);
|
|
1676
|
+
const place = context.places.get(spec.location);
|
|
1677
|
+
if (spec.feature !== void 0 && place !== void 0 && !place.features.some((feature) => feature.key === spec.feature)) problems.push(`${where}: ${place.name} has no feature "${spec.feature}"`);
|
|
1678
|
+
} else if (spec.feature !== void 0) problems.push(`${where}: a feature needs a location`);
|
|
1679
|
+
if (character === void 0 || start === void 0 || end === void 0) return [];
|
|
1680
|
+
return [{
|
|
1681
|
+
character,
|
|
1682
|
+
window: {
|
|
1683
|
+
days: [],
|
|
1684
|
+
on: [spec.date],
|
|
1685
|
+
start,
|
|
1686
|
+
end,
|
|
1687
|
+
activity: spec.activity.trim(),
|
|
1688
|
+
interruptible: spec.interruptible ?? true,
|
|
1689
|
+
...spec.location === void 0 ? {} : { location: spec.location },
|
|
1690
|
+
...spec.feature === void 0 ? {} : { featureKey: spec.feature },
|
|
1691
|
+
...spec.position === void 0 || spec.position.trim() === "" ? {} : { position: spec.position.trim() }
|
|
1692
|
+
}
|
|
1693
|
+
}];
|
|
1655
1694
|
})
|
|
1656
1695
|
};
|
|
1657
1696
|
}
|
|
@@ -1698,6 +1737,17 @@ function writeAgenda(target, prepared, turn, placeId) {
|
|
|
1698
1737
|
})));
|
|
1699
1738
|
writes += 1;
|
|
1700
1739
|
}
|
|
1740
|
+
for (const { character, window } of prepared.exceptions) {
|
|
1741
|
+
const date = window.on[0];
|
|
1742
|
+
const kept = target.routines.list(character).filter((existing) => !isExceptionOn(existing.on, date));
|
|
1743
|
+
if (kept.length + 1 > 24) throw new InvalidEditError([`routine_exceptions: the character's day already has 24 windows`]);
|
|
1744
|
+
const { location, ...rest } = window;
|
|
1745
|
+
target.routines.replace(character, [{
|
|
1746
|
+
...rest,
|
|
1747
|
+
...location === void 0 ? {} : { locationId: placeId(location) }
|
|
1748
|
+
}, ...kept]);
|
|
1749
|
+
writes += 1;
|
|
1750
|
+
}
|
|
1701
1751
|
return writes;
|
|
1702
1752
|
}
|
|
1703
1753
|
//#endregion
|
|
@@ -3553,6 +3603,17 @@ function parseRecordsEdit(value) {
|
|
|
3553
3603
|
}
|
|
3554
3604
|
return [parsed.definition];
|
|
3555
3605
|
}),
|
|
3606
|
+
routineExceptions: array("routine_exceptions").map((entry) => defined({
|
|
3607
|
+
character: text(entry, "character") ?? "",
|
|
3608
|
+
date: text(entry, "date") ?? "",
|
|
3609
|
+
activity: text(entry, "activity") ?? "",
|
|
3610
|
+
from: text(entry, "from"),
|
|
3611
|
+
to: text(entry, "to"),
|
|
3612
|
+
location: text(entry, "location"),
|
|
3613
|
+
feature: text(entry, "feature"),
|
|
3614
|
+
position: text(entry, "position"),
|
|
3615
|
+
interruptible: bool(entry, "interruptible")
|
|
3616
|
+
})),
|
|
3556
3617
|
routines: array("routines").map((entry) => ({
|
|
3557
3618
|
character: text(entry, "character") ?? "",
|
|
3558
3619
|
windows: Array.isArray(entry["windows"]) ? entry["windows"].filter(isObject$1).map((window) => defined({
|
|
@@ -4229,6 +4290,42 @@ function recordsEditSchema(options = {}) {
|
|
|
4229
4290
|
additionalProperties: false
|
|
4230
4291
|
}
|
|
4231
4292
|
},
|
|
4293
|
+
routine_exceptions: {
|
|
4294
|
+
type: "array",
|
|
4295
|
+
description: "A day on which a character does something other than its routine says (ill in bed, away on an errand, a day off): the date (YYYY-MM-DD, story-local), what it does and where; it takes the place of the routine on that date only. Setting the same date again replaces it.",
|
|
4296
|
+
items: {
|
|
4297
|
+
type: "object",
|
|
4298
|
+
properties: {
|
|
4299
|
+
character,
|
|
4300
|
+
date: {
|
|
4301
|
+
type: "string",
|
|
4302
|
+
description: "YYYY-MM-DD."
|
|
4303
|
+
},
|
|
4304
|
+
activity: {
|
|
4305
|
+
type: "string",
|
|
4306
|
+
description: "What it does that day: \"keeps to bed with a fever\"."
|
|
4307
|
+
},
|
|
4308
|
+
from: {
|
|
4309
|
+
type: "string",
|
|
4310
|
+
description: "HH:MM; leave out with to for the whole day."
|
|
4311
|
+
},
|
|
4312
|
+
to: {
|
|
4313
|
+
type: "string",
|
|
4314
|
+
description: "HH:MM."
|
|
4315
|
+
},
|
|
4316
|
+
location: placeKey,
|
|
4317
|
+
feature: { type: "string" },
|
|
4318
|
+
position: { type: "string" },
|
|
4319
|
+
interruptible: { type: "boolean" }
|
|
4320
|
+
},
|
|
4321
|
+
required: [
|
|
4322
|
+
"character",
|
|
4323
|
+
"date",
|
|
4324
|
+
"activity"
|
|
4325
|
+
],
|
|
4326
|
+
additionalProperties: false
|
|
4327
|
+
}
|
|
4328
|
+
},
|
|
4232
4329
|
engagement_edits: {
|
|
4233
4330
|
type: "array",
|
|
4234
4331
|
description: "An engagement that moved on (the ids are in read_records): it was kept, missed, cancelled, or put off. Give only what changes.",
|