@dsh-agentic-roleplay/core 0.3.0 → 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/lib/authoring.js +18 -223
- package/lib/client.js +903 -478
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/{deliver--uMhC6oO.js → deliver-BDW5WZvc.js} +579 -195
- package/lib/{documents-7GMc5NnW.js → documents-DtlY2IRt.js} +857 -12
- package/lib/{gallery-DUeBMHQX.js → gallery-DACG5eh2.js} +2 -2
- package/lib/{generator-HPifO3Kk.js → generator-DGYcLMp7.js} +2 -2
- package/lib/images.js +3 -3
- package/lib/index.js +181 -11
- package/lib/{narration-CKZTk5UE.js → narration-5ig7Dg28.js} +3 -2
- package/lib/orchestration.js +366 -274
- package/lib/{packs-alJTiDM2.js → packs-CkRZDCsV.js} +49 -5
- package/lib/{presenter-agent-PX1WVaJB.js → presenter-agent-PK9JYExk.js} +3 -3
- package/package.json +4 -4
- package/packs/scene/strip.js +1 -1
- package/prompts/en/roleplay/character-decide.md +1 -1
- package/prompts/en/roleplay/character-rules.md +1 -1
- package/prompts/en/roleplay/chronicler.md +1 -1
- package/prompts/en/roleplay/game-master.md +1 -1
- package/prompts/en/roleplay/reflection.md +2 -2
- package/prompts/en/roleplay/style.md +1 -1
- package/prompts/en/roleplay/suggester.md +1 -1
- package/prompts/en/translate/document.md +6 -0
- package/prompts/en/translate/glossary.md +5 -0
- package/prompts/en/translate/notice.md +2 -0
- package/prompts/zh/roleplay/character-decide.md +1 -1
- package/prompts/zh/roleplay/character-rules.md +1 -1
- package/prompts/zh/roleplay/chronicler.md +1 -1
- package/prompts/zh/roleplay/game-master.md +1 -1
- package/prompts/zh/roleplay/reflection.md +2 -2
- package/prompts/zh/roleplay/style.md +1 -1
- package/prompts/zh/roleplay/suggester.md +1 -1
- package/prompts/zh/translate/document.md +6 -0
- package/prompts/zh/translate/glossary.md +5 -0
- package/prompts/zh/translate/notice.md +2 -0
|
@@ -1,17 +1,225 @@
|
|
|
1
1
|
import { r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import {
|
|
2
|
+
import { K as SessionNotFoundError, P as inheritPrompts, S as wrongLanguage, i as inheritPacks } from "./packs-CkRZDCsV.js";
|
|
3
3
|
import "./src-CWTNeL6Y.js";
|
|
4
|
-
import { A as runChild, D as childSampling, E as childModel, j as estimateAnswer, k as childTrace, u as inheritImages } from "./generator-
|
|
4
|
+
import { A as runChild, D as childSampling, E as childModel, j as estimateAnswer, k as childTrace, u as inheritImages } from "./generator-DGYcLMp7.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
8
|
-
import { DAY, MINUTE, SECOND, characterKey, clockTime, dayPart, describeDuration, describeInstant, isSessionId, localTime, locationKey, mentioned, nextTimeOfDay, overlap, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
|
|
8
|
+
import { DAY, MINUTE, SECOND, addLocalDays, characterKey, clockTime, dayPart, describeDuration, describeInstant, holidaysOn, isSessionId, localTime, locationKey, mentioned, nextTimeOfDay, overlap, readCalendar, seasonOf, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
|
|
9
9
|
//#region ../dsh-roleplay-model/src/memory.ts
|
|
10
10
|
const MEMORY_KINDS = [
|
|
11
11
|
"belief",
|
|
12
12
|
"relationship",
|
|
13
13
|
"knowledge"
|
|
14
14
|
];
|
|
15
|
+
/** How sure a character is of what it believes, from least to most. */
|
|
16
|
+
const MEMORY_CONFIDENCES = [
|
|
17
|
+
"doubtful",
|
|
18
|
+
"likely",
|
|
19
|
+
"sure"
|
|
20
|
+
];
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region ../dsh-roleplay-model/src/messages-zh.ts
|
|
23
|
+
/** The Chinese of the texts built in code, by the English that stands in the code. A `{name}` is filled in and must stand in both. */
|
|
24
|
+
const ZH = {
|
|
25
|
+
", ": ",",
|
|
26
|
+
"; ": ";",
|
|
27
|
+
": ": ":",
|
|
28
|
+
".": "。",
|
|
29
|
+
" and ": "和",
|
|
30
|
+
"doubtful": "存疑",
|
|
31
|
+
"likely": "较有把握",
|
|
32
|
+
"sure": "确信",
|
|
33
|
+
"open": "畅通",
|
|
34
|
+
"locked": "已上锁",
|
|
35
|
+
"blocked": "被堵住",
|
|
36
|
+
"night": "夜里",
|
|
37
|
+
"morning": "上午",
|
|
38
|
+
"afternoon": "下午",
|
|
39
|
+
"evening": "傍晚",
|
|
40
|
+
"spring": "春季",
|
|
41
|
+
"summer": "夏季",
|
|
42
|
+
"autumn": "秋季",
|
|
43
|
+
"winter": "冬季",
|
|
44
|
+
"today is {holidays}": "今天是{holidays}",
|
|
45
|
+
"Summary": "概述",
|
|
46
|
+
"Personality": "性格",
|
|
47
|
+
"Background": "背景",
|
|
48
|
+
"Appearance": "外貌",
|
|
49
|
+
"How you speak": "说话方式",
|
|
50
|
+
"You are {name}.": "你是{name}。",
|
|
51
|
+
"You are also called {names}.": "你也被称作{names}。",
|
|
52
|
+
"age: {value}": "年龄:{value}",
|
|
53
|
+
"gender: {value}": "性别:{value}",
|
|
54
|
+
"pronouns: {value}": "代词:{value}",
|
|
55
|
+
"Situation:": "当前情形:",
|
|
56
|
+
"Now: {time}.": "现在是:{time}。",
|
|
57
|
+
"Where you are:": "你所在之处:",
|
|
58
|
+
"Present:": "在场的人:",
|
|
59
|
+
" (you)": "(你)",
|
|
60
|
+
"What you know is coming:": "你知道即将发生的事:",
|
|
61
|
+
"Just now you notice:": "此刻你注意到:",
|
|
62
|
+
"How you are (what you can tell of yourself):": "你的状态(你自己能感觉到的):",
|
|
63
|
+
"What you can tell of the others here:": "你能看出在场其他人的情况:",
|
|
64
|
+
"What you have on you:": "你身上带着:",
|
|
65
|
+
"Things here: ": "这里有:",
|
|
66
|
+
"Ways out: ": "出路:",
|
|
67
|
+
"Lying about: ": "散落在周围的:",
|
|
68
|
+
"hidden": "隐蔽",
|
|
69
|
+
" holding {things}": ",里面有{things}",
|
|
70
|
+
"; and {count} more": ";另有{count}项",
|
|
71
|
+
"at {feature}": "在{feature}",
|
|
72
|
+
"; and {count} more you can recall if needed": ";另有{count}项,需要时你可以回想起来",
|
|
73
|
+
"What you know exists (this does not tell you where it is now or what state it is in):": "你知道存在的事物(这并不说明它现在在哪里、处于什么状态):",
|
|
74
|
+
"People: ": "人物:",
|
|
75
|
+
"Factions: ": "组织:",
|
|
76
|
+
"Places: ": "地点:",
|
|
77
|
+
"Routes: ": "路径:",
|
|
78
|
+
"Things: ": "物品:",
|
|
79
|
+
"Your day and what you are after (plans, not orders: keep them, put them off or drop them as the moment and your character suggest):": "你的日程与你想达成的事(只是计划,不是命令:依当下情形和你的性格,可以照做、推迟或放弃):",
|
|
80
|
+
"Your day, now: {activity}{place}, until {until}{note}.": "你此刻的日程:{activity}{place},持续到{until}{note}。",
|
|
81
|
+
"Your day, next: {activity}{place}, from {from}.": "你接下来的日程:{activity}{place},{from}开始。",
|
|
82
|
+
" at {place}": ",在{place}",
|
|
83
|
+
" (not something you would drop lightly)": "(你不会轻易放下)",
|
|
84
|
+
", with {names}": ",与{names}一起",
|
|
85
|
+
"You were to: {title}{place}{with}, at {at}, which has passed and is still open.": "你本应:{title}{place}{with},时间是{at},已经过了,事情仍未了结。",
|
|
86
|
+
"You are due to: {title}{place}{with}, at {at}.": "你约定要:{title}{place}{with},时间是{at}。",
|
|
87
|
+
"What you are after:": "你想达成的事:",
|
|
88
|
+
", by {deadline}, which has passed": ",限期{deadline},已过",
|
|
89
|
+
", by {deadline}": ",限期{deadline}",
|
|
90
|
+
" Next: {plan}.": " 下一步:{plan}。",
|
|
91
|
+
"How you stand with people who bear on this moment (your own view, not objective fact):": "你与和此刻相关的人的关系(是你自己的看法,不是客观事实):",
|
|
92
|
+
" (here)": "(在场)",
|
|
93
|
+
" (not here)": "(不在场)",
|
|
94
|
+
"knows them well": "很了解对方",
|
|
95
|
+
"barely knows them": "几乎不了解对方",
|
|
96
|
+
"trusts them": "信任对方",
|
|
97
|
+
"distrusts them": "不信任对方",
|
|
98
|
+
"is fond of them": "喜欢对方",
|
|
99
|
+
"dislikes them": "不喜欢对方",
|
|
100
|
+
"things are strained between them": "彼此关系紧张",
|
|
101
|
+
"Your affiliations (their goals are pressures and commitments, not commands):": "你的所属组织(其目标是压力和承诺,不是命令):",
|
|
102
|
+
"member": "成员",
|
|
103
|
+
" Goals: {goals}.": " 目标:{goals}。",
|
|
104
|
+
"- {name}: {position}; {status}; commitment {commitment}.": "- {name}:{position};{status};投入程度 {commitment}。",
|
|
105
|
+
" Your view: {attitude}.": " 你的看法:{attitude}。",
|
|
106
|
+
"What you remember that bears on this (only what you took in yourself; do not claim to remember more, and be unsure of what is fuzzy):": "你记得的、与此相关的事(只限你自己亲身经历的;不要声称记得更多,模糊的地方要保持不确定):",
|
|
107
|
+
"What you remember that bears on this: nothing comes to mind.": "你记得的、与此相关的事:想不起任何事。",
|
|
108
|
+
"some time ago": "一段时间以前",
|
|
109
|
+
"just now": "刚才",
|
|
110
|
+
"1 day ago": "1天前",
|
|
111
|
+
"{amount} days ago": "{amount}天前",
|
|
112
|
+
"1 hour ago": "1小时前",
|
|
113
|
+
"{amount} hours ago": "{amount}小时前",
|
|
114
|
+
"1 minute ago": "1分钟前",
|
|
115
|
+
"{amount} minutes ago": "{amount}分钟前",
|
|
116
|
+
"the details are fuzzy": "细节已经模糊",
|
|
117
|
+
"you barely remember": "你几乎记不清了",
|
|
118
|
+
"you are sure of it": "你对此确信无疑",
|
|
119
|
+
"you doubt it": "你对此存疑",
|
|
120
|
+
"something you have seen since speaks against it": "此后你所见所闻有与之相悖的地方",
|
|
121
|
+
"it comes to mind with the rest": "它和其余的事一起浮现在脑海",
|
|
122
|
+
"Earlier in this scene, before this moment:": "这一幕此刻之前发生的事:",
|
|
123
|
+
"What just happened, and what you are reacting to:": "刚才发生的事,以及你在回应的是什么:",
|
|
124
|
+
"- {name} intended: {intent} ({result}) {summary}": "- {name}打算:{intent}({result}){summary}",
|
|
125
|
+
"- {name} said \"{utterance}\" and intended: {intent} ({result}) {summary}": "- {name}说了“{utterance}”,并打算:{intent}({result}){summary}",
|
|
126
|
+
"Your earlier intent did not work out: {intent}\nYou are trying again, knowing the above. Decide again what you do now.": "你先前的打算没有成功:{intent}\n你带着上面这些再试一次。重新决定你现在做什么。",
|
|
127
|
+
"Character: {name}{summary}": "角色:{name}{summary}",
|
|
128
|
+
"What they believe now:": "他们现在的看法:",
|
|
129
|
+
"(nothing yet)": "(暂时没有)",
|
|
130
|
+
"What they have taken in since:": "他们此后经历的事:",
|
|
131
|
+
"Sort their memory.": "请整理他们的记忆。",
|
|
132
|
+
"not acceptable: {problems}": "不可接受:{problems}",
|
|
133
|
+
"{kind}, importance {importance}, {confidence}{about}{dispute}": "{kind},重要性 {importance},{confidence}{about}{dispute}",
|
|
134
|
+
", about {names}": ",关于{names}",
|
|
135
|
+
", something taken in since speaks against it": ",此后经历的事与之相悖",
|
|
136
|
+
"add: at most {max} new beliefs in one pass; merge or choose": "add:一次最多 {max} 条新看法;请合并或取舍",
|
|
137
|
+
"at most {max} changes in one pass": "一次最多 {max} 处修改",
|
|
138
|
+
"{where}: there is no thing it took in numbered {id}": "{where}:没有编号为 {id} 的经历",
|
|
139
|
+
"{where}: confidence is one of {options}": "{where}:confidence 须为 {options} 之一",
|
|
140
|
+
"{where}: unknown kind \"{kind}\"": "{where}:未知的 kind “{kind}”",
|
|
141
|
+
"{where}: say what it believes": "{where}:请写出它相信什么",
|
|
142
|
+
"{where}: at most {max} characters; say it shorter": "{where}:最多 {max} 个字符;请写得更短",
|
|
143
|
+
"{where}: importance runs from {min} to {max}": "{where}:importance 取值为 {min} 到 {max}",
|
|
144
|
+
"{where}: there is no belief numbered {id}": "{where}:没有编号为 {id} 的看法",
|
|
145
|
+
"{where}: one passing moment is not yet a belief; rest it on things from at least two different turns, or on one event that turned the story": "{where}:一个转瞬即逝的瞬间还不是看法;请以至少两个不同回合的经历为依据,或以一件扭转了故事的事件为依据",
|
|
146
|
+
"{where}: to be sure of something it must rest on things from at least two different turns": "{where}:要对某事确信,必须以至少两个不同回合的经历为依据",
|
|
147
|
+
"{where}: \"{name}\" is not a character; name them as they are named": "{where}:“{name}”不是角色;请使用他们的名字",
|
|
148
|
+
"{where}: belief {id} is already changed in this pass": "{where}:看法 {id} 在这一轮中已经修改过",
|
|
149
|
+
"{where}: say what it took in since that bears on it": "{where}:请写出此后与之相关的经历",
|
|
150
|
+
"{where}: thing {id} came before the belief was formed; cite what came after": "{where}:经历 {id} 发生在看法形成之前;请引用之后发生的事",
|
|
151
|
+
"{where}: say what changes": "{where}:请写出有何改变",
|
|
152
|
+
"{where}: the text must be there and at most {max} characters": "{where}:必须有文字,且最多 {max} 个字符",
|
|
153
|
+
"{where}: a belief that something contradicts must be doubted: lower its confidence": "{where}:被事实相悖的看法必须存疑:请降低其 confidence",
|
|
154
|
+
"{where}: to doubt a belief, name what contradicts it in contradicted_by": "{where}:要对看法存疑,请在 contradicted_by 中写明与之相悖的经历",
|
|
155
|
+
"{where}: merge into a belief that stays": "{where}:请合并到保留的看法中",
|
|
156
|
+
"Time: {time}.": "时间:{time}。",
|
|
157
|
+
"The story's time moves only as you say: each round takes what you give it (elapsed_seconds in resolve_round, or the default), and advance_time skips ahead.": "故事的时间只按你说的推进:每一轮耗时由你给定(resolve_round 的 elapsed_seconds,或取默认值),advance_time 可以跳过一段时间。",
|
|
158
|
+
"The player was away for {duration} of real time and the story went on meanwhile: characters have been about their own business, so do not assume anyone is where or as the player left them unless the records say so.": "玩家离开了{duration}的真实时间,其间故事仍在继续:角色们各忙各的事,除非记录另有说明,不要假定任何人还在玩家离开时的位置或状态。",
|
|
159
|
+
"The story's time follows the real clock: it cannot be skipped, and each round takes as long as it really took.": "故事时间跟随真实时钟:无法跳过,每一轮耗时就是它实际花费的时间。",
|
|
160
|
+
"By their routines since you last looked: {moves}.": "按各自的日程,自你上次查看以来:{moves}。",
|
|
161
|
+
"{name} went to {place} ({activity})": "{name}去了{place}({activity})",
|
|
162
|
+
"With the player's character, and their days: {days}. The characters decide for themselves whether to keep to their day; the moment may keep them.": "与玩家角色在一起的人及其日程:{days}。是否照日程行事由角色自己决定;当下的情形也可能拖住他们。",
|
|
163
|
+
", at {place}": ",在{place}",
|
|
164
|
+
"\"{title}\" ({with}{place}) was due {when} and is still open": "“{title}”({with}{place})原定{when},仍未了结",
|
|
165
|
+
"\"{title}\" ({with}{place}) is due {when}": "“{title}”({with}{place})定于{when}",
|
|
166
|
+
"Commitments due soon or overdue: {entries}.": "即将到期或已逾期的约定:{entries}。",
|
|
167
|
+
"named in the move": "被这一步行动点到",
|
|
168
|
+
"in the scene": "在场",
|
|
169
|
+
"own goal: {goal}": "自身目标:{goal}",
|
|
170
|
+
"faction pressure: {goal}": "组织压力:{goal}",
|
|
171
|
+
"high tension toward the player": "对玩家高度紧张",
|
|
172
|
+
"distrusts the player": "不信任玩家",
|
|
173
|
+
"cares about the player": "在意玩家",
|
|
174
|
+
"dislikes the player": "不喜欢玩家",
|
|
175
|
+
"Likely characters to activate, in priority order (advice only; activate only whoever the moment actually reaches):": "可能需要启动的角色,按优先级排列(仅供参考;只启动当下真正牵涉到的人):",
|
|
176
|
+
"socially implicated": "社交上被牵涉",
|
|
177
|
+
"The player's character is in {place}": "玩家角色在{place}",
|
|
178
|
+
"Characters here:": "在这里的角色:",
|
|
179
|
+
"Characters elsewhere (they perceive nothing here unless the moment reaches them):": "在别处的角色(除非当下波及他们,否则感知不到这里的事):",
|
|
180
|
+
"{member} - in {place} ({key})": "{member} - 在{place}({key})",
|
|
181
|
+
"Characters with no place (not part of this scene; they cannot be asked to act):": "没有所在地点的角色(不属于这一幕;不能让他们行动):",
|
|
182
|
+
"the player's character, \"{key}\"": "玩家角色,“{key}”",
|
|
183
|
+
"acts through \"{key}\"": "通过“{key}”行动",
|
|
184
|
+
"Currently: {state}": "目前:{state}",
|
|
185
|
+
"Scene before turn {turn}:": "第 {turn} 回合之前的场景:",
|
|
186
|
+
"What characters have on them:": "角色们身上带着:",
|
|
187
|
+
"The world acted since the last turn, by itself:": "自上一回合以来,世界自行发生的事:",
|
|
188
|
+
"Known beforehand, still to come (who knows of it; it will happen by itself when its time comes):": "事先已知、尚未发生的事(谁知道;时候到了会自行发生):",
|
|
189
|
+
"[known to {who}]": "[知情者:{who}]",
|
|
190
|
+
"Weave these into the story when it fits, then say you did with addressed in narrate (each stays for a few turns and is then let go):": "合适时把这些织入故事,然后在 narrate 的 addressed 中说明已处理(每条会保留几个回合,之后放弃):",
|
|
191
|
+
"What the story keeps track of (change it with variable_changes in an outcome when what happened calls for it):": "故事追踪的内容(发生的事需要时,在结果中用 variable_changes 修改):",
|
|
192
|
+
"Still open in the story:": "故事中仍未了结的事:",
|
|
193
|
+
"Earlier events that bear on what the player just did (from the records of the story):": "与玩家刚才的行动相关的早先事件(来自故事记录):",
|
|
194
|
+
"turn {turn}": "第 {turn} 回合",
|
|
195
|
+
"You were to {title}, at {when}": "你本应{title},时间是{when}",
|
|
196
|
+
"You were to {title} at {place}, at {when}": "你本应在{place}:{title},时间是{when}",
|
|
197
|
+
" ({note})": "({note})",
|
|
198
|
+
"It is {now} now and the time has passed.": "现在是{now},时间已经过了。",
|
|
199
|
+
"It is {now} now.": "现在是{now}。",
|
|
200
|
+
"It was with: {who}.": "同你一起的有:{who}。",
|
|
201
|
+
"You are not with the player's character, and nothing of this happens in front of anyone: decide what you do about it.": "你不和玩家的角色在一起,这件事也不会发生在任何人面前:决定你要怎么处理。",
|
|
202
|
+
"The time you had for \"{goal}\" has passed ({when}; it is {now} now)": "你为“{goal}”预留的时间已过({when};现在是{now})",
|
|
203
|
+
"You are not with the player's character and nothing of this happens in front of anyone: decide what you do about it.": "你不和玩家的角色在一起,这件事也不会发生在任何人面前:决定你要怎么处理。",
|
|
204
|
+
"{names} noticed: {text}": "{names}注意到:{text}",
|
|
205
|
+
"{name} went to {place}.": "{name}去了{place}。"
|
|
206
|
+
};
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region ../dsh-roleplay-model/src/messages.ts
|
|
209
|
+
/** The language a setting such as `zh-CN` or `en` stands for; English when it is none that is known. */
|
|
210
|
+
function languageOf(code) {
|
|
211
|
+
return (code ?? "").trim().toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
212
|
+
}
|
|
213
|
+
const fill = (template, values) => values === void 0 ? template : template.replace(/\{(\w+)\}/g, (whole, name) => name in values ? String(values[name]) : whole);
|
|
214
|
+
const CATALOGUES = { zh: ZH };
|
|
215
|
+
/**
|
|
216
|
+
* 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
|
|
217
|
+
* the others; a text a language lacks is told in English, and a test keeps that from happening.
|
|
218
|
+
*/
|
|
219
|
+
function translator(language) {
|
|
220
|
+
const catalogue = language === "en" ? void 0 : CATALOGUES[language];
|
|
221
|
+
return (text, values) => fill(catalogue?.[text] ?? text, values);
|
|
222
|
+
}
|
|
15
223
|
//#endregion
|
|
16
224
|
//#region src/host/orchestration/protocol.ts
|
|
17
225
|
const COMMITMENTS = [
|
|
@@ -168,14 +376,23 @@ function referent(character) {
|
|
|
168
376
|
//#region src/host/clock/story-clock.ts
|
|
169
377
|
var ClockError = class extends Error {};
|
|
170
378
|
/** A moment as it is told next to `now`: the clock when it is the same day, the date as well when it is not. */
|
|
171
|
-
function describeWhen(instant, now, zone) {
|
|
379
|
+
function describeWhen(instant, now, zone, language = "en") {
|
|
172
380
|
const a = localTime(instant, zone);
|
|
173
381
|
const b = localTime(now, zone);
|
|
174
|
-
return a.year === b.year && a.month === b.month && a.day === b.day ? clockTime(instant, zone) : describeInstant(instant, zone);
|
|
382
|
+
return a.year === b.year && a.month === b.month && a.day === b.day ? clockTime(instant, zone) : describeInstant(instant, zone, language);
|
|
175
383
|
}
|
|
176
|
-
/**
|
|
177
|
-
|
|
178
|
-
|
|
384
|
+
/**
|
|
385
|
+
* The time in a sentence: the day and date, the clock, and the part of the day; and, when the world has a calendar, the season and the holidays that
|
|
386
|
+
* fall on the day.
|
|
387
|
+
*/
|
|
388
|
+
function describeTime(time, language = "en") {
|
|
389
|
+
const { calendar } = time;
|
|
390
|
+
const tr = translator(language);
|
|
391
|
+
const base = `${describeInstant(time.now, time.zone, language)} (${tr(dayPart(localTime(time.now, time.zone).minuteOfDay))})`;
|
|
392
|
+
if (calendar === void 0 || calendar.holidays.length === 0 && calendar.hemisphere === "north") return base;
|
|
393
|
+
const day = addLocalDays(time.now, time.zone, 0);
|
|
394
|
+
const holidays = holidaysOn(calendar, day).map((holiday) => holiday.name);
|
|
395
|
+
return `${base}${tr(", ")}${tr(seasonOf(day, calendar.hemisphere))}${holidays.length === 0 ? "" : `${tr("; ")}${tr("today is {holidays}", { holidays: holidays.join(tr(", ")) })}`}`;
|
|
179
396
|
}
|
|
180
397
|
/** The time zone the story is read in. */
|
|
181
398
|
const zoneOf = (config) => config.timeZone === "" ? "UTC" : config.timeZone;
|
|
@@ -193,14 +410,18 @@ function ensure(session, config, turn, wall) {
|
|
|
193
410
|
session.clock.resync("simulated", Math.max(current.now, wall), turn, "the story's time was detached from the real clock");
|
|
194
411
|
return session.clock.get() ?? current;
|
|
195
412
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
413
|
+
function timeOf(session, state, config) {
|
|
414
|
+
const calendar = session.metadata === void 0 ? void 0 : readCalendar(session.metadata);
|
|
415
|
+
return {
|
|
416
|
+
mode: state.mode,
|
|
417
|
+
now: state.now,
|
|
418
|
+
zone: zoneOf(config),
|
|
419
|
+
...calendar === void 0 || calendar.holidays.length === 0 && calendar.hemisphere === "north" ? {} : { calendar }
|
|
420
|
+
};
|
|
421
|
+
}
|
|
201
422
|
/** What time it is, without letting any pass. */
|
|
202
423
|
function readTime(session, config, turn, wall) {
|
|
203
|
-
return session.transaction(() => timeOf(ensure(session, config, turn, wall), config));
|
|
424
|
+
return session.transaction(() => timeOf(session, ensure(session, config, turn, wall), config));
|
|
204
425
|
}
|
|
205
426
|
/**
|
|
206
427
|
* The start of a turn. Following the wall clock, the time since the last turn passed outside the story:
|
|
@@ -218,14 +439,14 @@ function beginTurn(session, config, turn, wall) {
|
|
|
218
439
|
reason: "between turns"
|
|
219
440
|
});
|
|
220
441
|
return {
|
|
221
|
-
time: timeOf({
|
|
442
|
+
time: timeOf(session, {
|
|
222
443
|
mode: "real",
|
|
223
444
|
now: wall
|
|
224
445
|
}, config),
|
|
225
446
|
away: wall - state.now
|
|
226
447
|
};
|
|
227
448
|
}
|
|
228
|
-
return { time: timeOf(state, config) };
|
|
449
|
+
return { time: timeOf(session, state, config) };
|
|
229
450
|
});
|
|
230
451
|
}
|
|
231
452
|
/**
|
|
@@ -301,6 +522,7 @@ function skipTime(session, config, turn, round, wall, request) {
|
|
|
301
522
|
}
|
|
302
523
|
//#endregion
|
|
303
524
|
//#region src/host/orchestration/defaults.ts
|
|
525
|
+
const ENGLISH = translator("en");
|
|
304
526
|
/** What the instructions say about how long each part of a character's answer may run. */
|
|
305
527
|
const limitVariables = (language) => {
|
|
306
528
|
const limits = answerLimits(language);
|
|
@@ -310,22 +532,22 @@ const limitVariables = (language) => {
|
|
|
310
532
|
utteranceLimit: limits.utterance
|
|
311
533
|
};
|
|
312
534
|
};
|
|
313
|
-
function describe(character) {
|
|
314
|
-
const lines = [
|
|
315
|
-
if (character.aliases.length > 0) lines.push(
|
|
535
|
+
function describe(character, tr) {
|
|
536
|
+
const lines = [tr("You are {name}.", { name: character.name })];
|
|
537
|
+
if (character.aliases.length > 0) lines.push(tr("You are also called {names}.", { names: character.aliases.join(tr(", ")) }));
|
|
316
538
|
const facts = [
|
|
317
|
-
character.age === void 0 ? void 0 :
|
|
318
|
-
character.gender === void 0 ? void 0 :
|
|
319
|
-
character.pronouns === void 0 ? void 0 :
|
|
539
|
+
character.age === void 0 ? void 0 : tr("age: {value}", { value: character.age }),
|
|
540
|
+
character.gender === void 0 ? void 0 : tr("gender: {value}", { value: character.gender }),
|
|
541
|
+
character.pronouns === void 0 ? void 0 : tr("pronouns: {value}", { value: character.pronouns })
|
|
320
542
|
].filter((fact) => fact !== void 0);
|
|
321
|
-
if (facts.length > 0) lines.push(facts.join("; ") + ".");
|
|
543
|
+
if (facts.length > 0) lines.push(facts.join(tr("; ")) + tr("."));
|
|
322
544
|
for (const [label, text] of [
|
|
323
545
|
["Summary", character.summary],
|
|
324
546
|
["Personality", character.personality],
|
|
325
547
|
["Background", character.background],
|
|
326
548
|
["Appearance", character.appearance],
|
|
327
549
|
["How you speak", character.speech.style]
|
|
328
|
-
]) if (text.trim() !== "") lines.push(`${label}: ${text.trim()}`);
|
|
550
|
+
]) if (text.trim() !== "") lines.push(`${tr(label)}${tr(": ")}${text.trim()}`);
|
|
329
551
|
return lines.join("\n");
|
|
330
552
|
}
|
|
331
553
|
/** At most this many features and ways out of a place are told at once. */
|
|
@@ -337,89 +559,127 @@ const sentence = (text) => {
|
|
|
337
559
|
/** At most this many things are listed at once: the rest are said to be there and left for a closer look. */
|
|
338
560
|
const SHOWN_ITEMS = 12;
|
|
339
561
|
/** One thing in a sentence: how many, what state it is in, where it is. */
|
|
340
|
-
function describeItem(item, { withKeys }) {
|
|
562
|
+
function describeItem(item, { withKeys }, tr = ENGLISH) {
|
|
341
563
|
const name = `${item.quantity > 1 ? `${item.quantity} ` : ""}${item.name}${item.quality === "" ? "" : ` (${item.quality})`}`;
|
|
342
564
|
const extra = [
|
|
343
|
-
item.hidden ? "hidden" : "",
|
|
565
|
+
item.hidden ? tr("hidden") : "",
|
|
344
566
|
item.state === void 0 ? "" : item.state,
|
|
345
567
|
item.where ?? ""
|
|
346
|
-
].filter((part) => part !== "").join(", ");
|
|
347
|
-
const inside = item.contents === void 0 ? "" :
|
|
568
|
+
].filter((part) => part !== "").join(tr(", "));
|
|
569
|
+
const inside = item.contents === void 0 ? "" : tr(" holding {things}", { things: item.contents.join(tr(", ")) });
|
|
348
570
|
return `${withKeys ? `${item.key}: ` : ""}${name}${extra === "" ? "" : ` [${extra}]`}${inside}`;
|
|
349
571
|
}
|
|
350
572
|
/** A list of things, capped. */
|
|
351
|
-
function describeItems(items, options) {
|
|
352
|
-
return `${items.slice(0, SHOWN_ITEMS).map((item) => describeItem(item, options)).join("; ")}${items.length > SHOWN_ITEMS ?
|
|
573
|
+
function describeItems(items, options, tr = ENGLISH) {
|
|
574
|
+
return `${items.slice(0, SHOWN_ITEMS).map((item) => describeItem(item, options, tr)).join(tr("; "))}${items.length > SHOWN_ITEMS ? tr("; and {count} more", { count: items.length - SHOWN_ITEMS }) : ""}`;
|
|
353
575
|
}
|
|
354
576
|
/** What someone in a place is told about it: what it is like, what can be pointed at, and the ways out. */
|
|
355
|
-
function describePlace(view, { withKeys }) {
|
|
577
|
+
function describePlace(view, { withKeys }, tr = ENGLISH) {
|
|
356
578
|
const { location, exits } = view;
|
|
357
579
|
const lines = [`${location.name}${withKeys ? ` (${view.key})` : ""}${location.description === "" ? "" : `: ${location.description}`}`];
|
|
358
580
|
if (location.features.length > 0) {
|
|
359
581
|
const shown = location.features.slice(0, SHOWN_FEATURES).map((feature) => `${withKeys ? `${feature.key}: ` : ""}${feature.name}${feature.description === "" ? "" : ` - ${sentence(feature.description)}`}`);
|
|
360
|
-
lines.push(
|
|
582
|
+
lines.push(`${tr("Things here: ")}${shown.join(tr("; "))}${location.features.length > SHOWN_FEATURES ? tr("; and {count} more", { count: location.features.length - SHOWN_FEATURES }) : ""}`);
|
|
361
583
|
}
|
|
362
584
|
if (exits.length > 0) {
|
|
363
|
-
const shown = exits.slice(0, SHOWN_EXITS).map(({ key, name, exit }) => `${withKeys ? `${key}: ` : ""}${name}${exit.description === "" ? "" : ` (${sentence(exit.description)})`}${exit.state === "open" ? "" : ` [${exit.state}${exit.note === "" ? "" : `: ${exit.note}`}]`}`);
|
|
364
|
-
lines.push(
|
|
585
|
+
const shown = exits.slice(0, SHOWN_EXITS).map(({ key, name, exit }) => `${withKeys ? `${key}: ` : ""}${name}${exit.description === "" ? "" : ` (${sentence(exit.description)})`}${exit.state === "open" ? "" : ` [${tr(exit.state)}${exit.note === "" ? "" : `: ${exit.note}`}]`}`);
|
|
586
|
+
lines.push(`${tr("Ways out: ")}${shown.join(tr("; "))}${exits.length > SHOWN_EXITS ? tr("; and {count} more", { count: exits.length - SHOWN_EXITS }) : ""}`);
|
|
365
587
|
}
|
|
366
|
-
if (view.items !== void 0 && view.items.length > 0) lines.push(
|
|
588
|
+
if (view.items !== void 0 && view.items.length > 0) lines.push(`${tr("Lying about: ")}${describeItems(view.items, { withKeys }, tr)}`);
|
|
367
589
|
return lines;
|
|
368
590
|
}
|
|
369
591
|
/** How long the player has to have been away for it to be worth telling the game master. */
|
|
370
592
|
const NOTICEABLE_ABSENCE = 5 * MINUTE;
|
|
371
593
|
/** What the game master is told about time at the start of a turn, and how it passes. */
|
|
372
|
-
function timeNotice(time) {
|
|
373
|
-
const now =
|
|
374
|
-
if (time.now.mode === "simulated") return `${now} The story's time moves only as you say: each round takes what you give it (elapsed_seconds in resolve_round, or the default), and advance_time skips ahead
|
|
375
|
-
|
|
594
|
+
function timeNotice(time, language, tr) {
|
|
595
|
+
const now = tr("Time: {time}.", { time: describeTime(time.now, language) });
|
|
596
|
+
if (time.now.mode === "simulated") return `${now} ${tr("The story's time moves only as you say: each round takes what you give it (elapsed_seconds in resolve_round, or the default), and advance_time skips ahead.")}`;
|
|
597
|
+
const away = time.away !== void 0 && time.away >= NOTICEABLE_ABSENCE ? ` ${tr("The player was away for {duration} of real time and the story went on meanwhile: characters have been about their own business, so do not assume anyone is where or as the player left them unless the records say so.", { duration: describeDuration(time.away, language) })}` : "";
|
|
598
|
+
return `${now} ${tr("The story's time follows the real clock: it cannot be skipped, and each round takes as long as it really took.")}${away}`;
|
|
376
599
|
}
|
|
377
600
|
/** What a character is told of its day, its commitments and what it is after. */
|
|
378
|
-
function describeAgenda(agenda, now) {
|
|
601
|
+
function describeAgenda(agenda, now, tr = ENGLISH, language = "en") {
|
|
379
602
|
const { zone } = agenda;
|
|
380
|
-
const
|
|
603
|
+
const when = (instant) => describeWhen(instant, now, zone, language);
|
|
604
|
+
const at = (place) => place === void 0 ? "" : tr(" at {place}", { place });
|
|
381
605
|
const lines = [];
|
|
382
|
-
if (agenda.now !== void 0) lines.push(
|
|
383
|
-
|
|
384
|
-
|
|
606
|
+
if (agenda.now !== void 0) lines.push(tr("Your day, now: {activity}{place}, until {until}{note}.", {
|
|
607
|
+
activity: agenda.now.activity,
|
|
608
|
+
place: at(agenda.now.place),
|
|
609
|
+
until: when(agenda.now.until),
|
|
610
|
+
note: agenda.now.interruptible ? "" : tr(" (not something you would drop lightly)")
|
|
611
|
+
}));
|
|
612
|
+
if (agenda.next !== void 0) lines.push(tr("Your day, next: {activity}{place}, from {from}.", {
|
|
613
|
+
activity: agenda.next.activity,
|
|
614
|
+
place: at(agenda.next.place),
|
|
615
|
+
from: when(agenda.next.at)
|
|
616
|
+
}));
|
|
617
|
+
for (const engagement of agenda.engagements) {
|
|
618
|
+
const values = {
|
|
619
|
+
title: engagement.title,
|
|
620
|
+
place: at(engagement.place),
|
|
621
|
+
with: engagement.with.length === 0 ? "" : tr(", with {names}", { names: engagement.with.join(tr(", ")) }),
|
|
622
|
+
at: when(engagement.at)
|
|
623
|
+
};
|
|
624
|
+
lines.push(engagement.overdue ? tr("You were to: {title}{place}{with}, at {at}, which has passed and is still open.", values) : tr("You are due to: {title}{place}{with}, at {at}.", values));
|
|
625
|
+
}
|
|
385
626
|
if (agenda.goals.length > 0) {
|
|
386
|
-
lines.push("What you are after:");
|
|
387
|
-
for (const goal of agenda.goals)
|
|
627
|
+
lines.push(tr("What you are after:"));
|
|
628
|
+
for (const goal of agenda.goals) {
|
|
629
|
+
const by = goal.deadline === void 0 ? "" : goal.overdue ? tr(", by {deadline}, which has passed", { deadline: when(goal.deadline) }) : tr(", by {deadline}", { deadline: when(goal.deadline) });
|
|
630
|
+
lines.push(`- ${goal.name} (${goal.type})${by}${goal.description === "" ? "" : `${tr(": ")}${sentence(goal.description)}`}${goal.plan.length === 0 ? "" : tr(" Next: {plan}.", { plan: goal.plan.join(tr("; ")) })}`);
|
|
631
|
+
}
|
|
388
632
|
}
|
|
389
633
|
return lines;
|
|
390
634
|
}
|
|
391
635
|
/** What the game master is told of the characters' days at the start of a turn; nothing when there is nothing to tell. */
|
|
392
|
-
function describeSceneAgenda(agenda, now) {
|
|
636
|
+
function describeSceneAgenda(agenda, now, tr = ENGLISH, language = "en") {
|
|
393
637
|
const lines = [];
|
|
394
|
-
|
|
395
|
-
if (agenda.
|
|
396
|
-
|
|
638
|
+
const join = (entries) => entries.join(tr("; "));
|
|
639
|
+
if (agenda.moved.length > 0) lines.push(tr("By their routines since you last looked: {moves}.", { moves: join(agenda.moved.map((move) => tr("{name} went to {place} ({activity})", {
|
|
640
|
+
name: move.name,
|
|
641
|
+
place: move.to,
|
|
642
|
+
activity: move.activity
|
|
643
|
+
}))) }));
|
|
644
|
+
if (agenda.here.length > 0) lines.push(tr("With the player's character, and their days: {days}. The characters decide for themselves whether to keep to their day; the moment may keep them.", { days: join(agenda.here.map((entry) => `${entry.name}${tr(": ")}${entry.note}`)) }));
|
|
645
|
+
if (agenda.engagements.length > 0) {
|
|
646
|
+
const entries = agenda.engagements.map((engagement) => {
|
|
647
|
+
const values = {
|
|
648
|
+
title: engagement.title,
|
|
649
|
+
with: engagement.with.join(tr(", ")),
|
|
650
|
+
place: engagement.place === void 0 ? "" : tr(", at {place}", { place: engagement.place }),
|
|
651
|
+
when: describeWhen(engagement.at, now, agenda.zone, language)
|
|
652
|
+
};
|
|
653
|
+
return engagement.overdue ? tr("\"{title}\" ({with}{place}) was due {when} and is still open", values) : tr("\"{title}\" ({with}{place}) is due {when}", values);
|
|
654
|
+
});
|
|
655
|
+
lines.push(tr("Commitments due soon or overdue: {entries}.", { entries: join(entries) }));
|
|
656
|
+
}
|
|
397
657
|
return lines.join("\n");
|
|
398
658
|
}
|
|
399
659
|
/** In words, how a character stands with another, from the numbers of its profile; nothing for what is unremarkable. */
|
|
400
|
-
function describeAttitude(relation) {
|
|
660
|
+
function describeAttitude(relation, tr = ENGLISH) {
|
|
401
661
|
return [
|
|
402
|
-
relation.familiarity >= .7 ? "knows them well" : relation.familiarity <= .15 ? "barely knows them" : "",
|
|
403
|
-
relation.trust >= .4 ? "trusts them" : relation.trust <= -.4 ? "distrusts them" : "",
|
|
404
|
-
relation.affinity >= .4 ? "is fond of them" : relation.affinity <= -.4 ? "dislikes them" : "",
|
|
405
|
-
relation.tension >= .5 ? "things are strained between them" : ""
|
|
406
|
-
].filter((part) => part !== "").join(", ");
|
|
662
|
+
relation.familiarity >= .7 ? tr("knows them well") : relation.familiarity <= .15 ? tr("barely knows them") : "",
|
|
663
|
+
relation.trust >= .4 ? tr("trusts them") : relation.trust <= -.4 ? tr("distrusts them") : "",
|
|
664
|
+
relation.affinity >= .4 ? tr("is fond of them") : relation.affinity <= -.4 ? tr("dislikes them") : "",
|
|
665
|
+
relation.tension >= .5 ? tr("things are strained between them") : ""
|
|
666
|
+
].filter((part) => part !== "").join(tr(", "));
|
|
407
667
|
}
|
|
408
|
-
function whereIs(member) {
|
|
668
|
+
function whereIs(member, tr = ENGLISH) {
|
|
409
669
|
const place = member.place;
|
|
410
670
|
if (place === void 0) return "";
|
|
411
|
-
return [place.position, place.feature === void 0 ? "" :
|
|
671
|
+
return [place.position, place.feature === void 0 ? "" : tr("at {feature}", { feature: place.feature.name })].filter((part) => part !== "").join(tr(", "));
|
|
412
672
|
}
|
|
413
|
-
function present(cast, self) {
|
|
673
|
+
function present(cast, self, tr) {
|
|
414
674
|
return cast.map((member) => {
|
|
415
675
|
const { key, character, state } = member;
|
|
416
676
|
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
417
677
|
const where = whereIs(member);
|
|
418
|
-
return `- ${key === self ? character.name : referent(character)}${key === self ? " (you)" : ""}${where === "" ? "" : ` (${where})`}${seen.length > 0 ?
|
|
678
|
+
return `- ${key === self ? character.name : referent(character)}${key === self ? tr(" (you)") : ""}${where === "" ? "" : ` (${where})`}${seen.length > 0 ? `${tr(": ")}${seen.join(tr("; "))}` : ""}`;
|
|
419
679
|
}).join("\n");
|
|
420
680
|
}
|
|
421
681
|
/** A bounded, advisory order for who is most likely to need a turn; reachability still governs activation. */
|
|
422
|
-
function describeActivationCandidates(cast, input, story) {
|
|
682
|
+
function describeActivationCandidates(cast, input, story, tr = ENGLISH) {
|
|
423
683
|
const player = cast.find((member) => member.character.control === "player");
|
|
424
684
|
if (player === void 0) return "";
|
|
425
685
|
const named = mentioned(input, cast.map((member) => member.character));
|
|
@@ -438,99 +698,115 @@ function describeActivationCandidates(cast, input, story) {
|
|
|
438
698
|
return {
|
|
439
699
|
member,
|
|
440
700
|
reasons: [
|
|
441
|
-
named.has(member.character.id) ? "named in the move" : "",
|
|
442
|
-
here ? "in the scene" : "",
|
|
443
|
-
(goal?.match ?? 0) >= 2 ?
|
|
444
|
-
(factionGoal?.match ?? 0) >= 2 ?
|
|
445
|
-
relation !== void 0 && relation.tension >= .5 ? "high tension toward the player" : "",
|
|
446
|
-
relation !== void 0 && relation.trust <= -.4 ? "distrusts the player" : "",
|
|
447
|
-
relation !== void 0 && Math.abs(relation.affinity) >= .4 ? relation.affinity > 0 ? "cares about the player" : "dislikes the player" : ""
|
|
701
|
+
named.has(member.character.id) ? tr("named in the move") : "",
|
|
702
|
+
here ? tr("in the scene") : "",
|
|
703
|
+
(goal?.match ?? 0) >= 2 ? tr("own goal: {goal}", { goal: goal.intent.name }) : "",
|
|
704
|
+
(factionGoal?.match ?? 0) >= 2 ? tr("faction pressure: {goal}", { goal: factionGoal.intent.name }) : "",
|
|
705
|
+
relation !== void 0 && relation.tension >= .5 ? tr("high tension toward the player") : "",
|
|
706
|
+
relation !== void 0 && relation.trust <= -.4 ? tr("distrusts the player") : "",
|
|
707
|
+
relation !== void 0 && Math.abs(relation.affinity) >= .4 ? relation.affinity > 0 ? tr("cares about the player") : tr("dislikes the player") : ""
|
|
448
708
|
].filter((reason) => reason !== ""),
|
|
449
709
|
score: (named.has(member.character.id) ? 4 : 0) + (here ? 2 : 0) + Math.min(2, (goal?.match ?? 0) / 2) + Math.min(2, (factionGoal?.match ?? 0) / 2) + (relation?.tension ?? 0) + Math.max(0, -(relation?.trust ?? 0)) * .5 + Math.abs(relation?.affinity ?? 0) * .5
|
|
450
710
|
};
|
|
451
711
|
}).filter((entry) => entry.score > 0).sort((a, b) => b.score - a.score || a.member.key.localeCompare(b.member.key)).slice(0, 5);
|
|
452
712
|
if (candidates.length === 0) return "";
|
|
453
|
-
return
|
|
454
|
-
}
|
|
455
|
-
function said(entry) {
|
|
456
|
-
return
|
|
713
|
+
return `${tr("Likely characters to activate, in priority order (advice only; activate only whoever the moment actually reaches):")}\n${candidates.map(({ member, reasons }) => `- ${member.character.name} (${member.key}): ${reasons.join(tr(", ")) || tr("socially implicated")}`).join("\n")}`;
|
|
714
|
+
}
|
|
715
|
+
function said(entry, tr) {
|
|
716
|
+
return entry.utterance === void 0 ? tr("- {name} intended: {intent} ({result}) {summary}", {
|
|
717
|
+
name: entry.name,
|
|
718
|
+
intent: entry.intent,
|
|
719
|
+
result: entry.result,
|
|
720
|
+
summary: entry.summary
|
|
721
|
+
}) : tr("- {name} said \"{utterance}\" and intended: {intent} ({result}) {summary}", {
|
|
722
|
+
name: entry.name,
|
|
723
|
+
utterance: entry.utterance,
|
|
724
|
+
intent: entry.intent,
|
|
725
|
+
result: entry.result,
|
|
726
|
+
summary: entry.summary
|
|
727
|
+
});
|
|
457
728
|
}
|
|
458
|
-
function age(at, now) {
|
|
459
|
-
if (at === void 0 || now === void 0) return "some time ago";
|
|
729
|
+
function age(at, now, tr) {
|
|
730
|
+
if (at === void 0 || now === void 0) return tr("some time ago");
|
|
460
731
|
const seconds = Math.max(0, Math.floor((now - at) / 1e3));
|
|
461
|
-
if (seconds < 60) return "just now";
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
name: "hour"
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
seconds: 60,
|
|
473
|
-
name: "minute"
|
|
474
|
-
}
|
|
475
|
-
].find((candidate) => seconds >= candidate.seconds);
|
|
476
|
-
const amount = Math.floor(seconds / unit.seconds);
|
|
477
|
-
return `${amount} ${unit.name}${amount === 1 ? "" : "s"} ago`;
|
|
478
|
-
}
|
|
479
|
-
/** What a character remembers, in the way it remembers it: what is faded or vague is told as such. */
|
|
480
|
-
function remembered(memories, now) {
|
|
732
|
+
if (seconds < 60) return tr("just now");
|
|
733
|
+
const amount = Math.floor(seconds / (seconds >= 86400 ? 86400 : seconds >= 3600 ? 3600 : 60));
|
|
734
|
+
if (seconds >= 86400) return amount === 1 ? tr("1 day ago") : tr("{amount} days ago", { amount });
|
|
735
|
+
if (seconds >= 3600) return amount === 1 ? tr("1 hour ago") : tr("{amount} hours ago", { amount });
|
|
736
|
+
return amount === 1 ? tr("1 minute ago") : tr("{amount} minutes ago", { amount });
|
|
737
|
+
}
|
|
738
|
+
/** What a character remembers, in the way it remembers it: what is faded or vague is told as such, and what it is sure or doubtful of. */
|
|
739
|
+
function remembered(memories, tr, now) {
|
|
481
740
|
return memories.map((memory) => {
|
|
482
|
-
|
|
741
|
+
const clarity = memory.clarity === "clear" ? [] : [memory.clarity === "faded" ? tr("the details are fuzzy") : tr("you barely remember")];
|
|
742
|
+
const sure = memory.confidence === "sure" ? [tr("you are sure of it")] : memory.confidence === "doubtful" ? [tr("you doubt it")] : [];
|
|
743
|
+
const against = memory.disputed === true ? [tr("something you have seen since speaks against it")] : [];
|
|
744
|
+
return `- (${[
|
|
745
|
+
age(memory.at, now, tr),
|
|
746
|
+
...clarity,
|
|
747
|
+
...sure,
|
|
748
|
+
...against,
|
|
749
|
+
...memory.linked === true ? [tr("it comes to mind with the rest")] : []
|
|
750
|
+
].join(tr(", "))}) ${memory.text}`;
|
|
483
751
|
}).join("\n");
|
|
484
752
|
}
|
|
485
753
|
/** Every character is told the same thing about the scene, plus who it is and what it remembers. */
|
|
486
754
|
const sharedContext = { brief(request) {
|
|
487
755
|
const { member, cast, situation, attempt, earlier, reaction, previous, memories, place, relationships, knowledge, affiliations, carrying, time, agenda } = request;
|
|
756
|
+
const language = languageOf(request.language);
|
|
757
|
+
const tr = translator(language);
|
|
758
|
+
const list = (entries) => entries.join(tr("; "));
|
|
488
759
|
const company = place === void 0 ? cast : place.here;
|
|
489
760
|
const sections = [
|
|
490
|
-
|
|
491
|
-
...time === void 0 ? [] : [
|
|
492
|
-
...place === void 0 ? [] : [
|
|
493
|
-
|
|
761
|
+
`${tr("Situation:")}\n${situation}`,
|
|
762
|
+
...time === void 0 ? [] : [tr("Now: {time}.", { time: describeTime(time, language) })],
|
|
763
|
+
...place === void 0 ? [] : [`${tr("Where you are:")}\n${describePlace(place, { withKeys: false }, tr).join("\n")}`],
|
|
764
|
+
`${tr("Present:")}\n${present(company, member.key, tr)}`
|
|
494
765
|
];
|
|
495
|
-
if (request.upcoming !== void 0 && request.upcoming.length > 0) sections.push(
|
|
496
|
-
if (request.cues !== void 0 && request.cues.length > 0) sections.push(
|
|
497
|
-
if (request.tracked !== void 0 && request.tracked.self !== "") sections.push(
|
|
498
|
-
if (request.tracked !== void 0 && request.tracked.others.length > 0) sections.push(
|
|
499
|
-
const day = agenda === void 0 || time === void 0 ? [] : describeAgenda(agenda, time.now);
|
|
500
|
-
if (day.length > 0) sections.push(
|
|
501
|
-
if (carrying !== void 0 && carrying.length > 0) sections.push(
|
|
502
|
-
if (relationships !== void 0 && relationships.length > 0) sections.push(
|
|
503
|
-
const attitude = describeAttitude(relation);
|
|
504
|
-
return `- ${relation.name}${relation.present ? " (here)" : " (not here)"} — ${relation.label}${relation.summary === "" ? "" :
|
|
766
|
+
if (request.upcoming !== void 0 && request.upcoming.length > 0) sections.push(`${tr("What you know is coming:")}\n${request.upcoming.map((entry) => `- ${entry.text}${entry.when === void 0 ? "" : ` (${entry.when})`}`).join("\n")}`);
|
|
767
|
+
if (request.cues !== void 0 && request.cues.length > 0) sections.push(`${tr("Just now you notice:")}\n${request.cues.map((cue) => `- ${cue}`).join("\n")}`);
|
|
768
|
+
if (request.tracked !== void 0 && request.tracked.self !== "") sections.push(`${tr("How you are (what you can tell of yourself):")}\n${request.tracked.self}`);
|
|
769
|
+
if (request.tracked !== void 0 && request.tracked.others.length > 0) sections.push(`${tr("What you can tell of the others here:")}\n${request.tracked.others.map((other) => `- ${other.name}: ${other.text}`).join("\n")}`);
|
|
770
|
+
const day = agenda === void 0 || time === void 0 ? [] : describeAgenda(agenda, time.now, tr, language);
|
|
771
|
+
if (day.length > 0) sections.push(`${tr("Your day and what you are after (plans, not orders: keep them, put them off or drop them as the moment and your character suggest):")}\n${day.join("\n")}`);
|
|
772
|
+
if (carrying !== void 0 && carrying.length > 0) sections.push(`${tr("What you have on you:")}\n${describeItems(carrying, { withKeys: false }, tr)}`);
|
|
773
|
+
if (relationships !== void 0 && relationships.length > 0) sections.push(`${tr("How you stand with people who bear on this moment (your own view, not objective fact):")}\n${relationships.map((relation) => {
|
|
774
|
+
const attitude = describeAttitude(relation, tr);
|
|
775
|
+
return `- ${relation.name}${relation.present ? tr(" (here)") : tr(" (not here)")} — ${relation.label}${relation.summary === "" ? "" : `${tr(": ")}${relation.summary}`}${attitude === "" ? "" : ` [${attitude}]`}`;
|
|
505
776
|
}).join("\n")}`);
|
|
506
|
-
if (affiliations !== void 0 && affiliations.length > 0) sections.push(
|
|
507
|
-
const position = [entry.role, entry.rank].filter(Boolean).join(", ") || "member";
|
|
508
|
-
const goals = entry.goals.length === 0 ? "" :
|
|
777
|
+
if (affiliations !== void 0 && affiliations.length > 0) sections.push(`${tr("Your affiliations (their goals are pressures and commitments, not commands):")}\n${affiliations.map((entry) => {
|
|
778
|
+
const position = [entry.role, entry.rank].filter(Boolean).join(tr(", ")) || tr("member");
|
|
779
|
+
const goals = entry.goals.length === 0 ? "" : tr(" Goals: {goals}.", { goals: list(entry.goals) });
|
|
509
780
|
const state = entry.publicState === "" ? "" : ` ${entry.publicState}`;
|
|
510
|
-
const attitude = entry.relationship === void 0 ? "" : describeAttitude(entry.relationship);
|
|
511
|
-
return
|
|
781
|
+
const attitude = entry.relationship === void 0 ? "" : describeAttitude(entry.relationship, tr);
|
|
782
|
+
return tr("- {name}: {position}; {status}; commitment {commitment}.", {
|
|
783
|
+
name: entry.name,
|
|
784
|
+
position,
|
|
785
|
+
status: entry.status,
|
|
786
|
+
commitment: entry.commitment.toFixed(2)
|
|
787
|
+
}) + `${state}${goals}${attitude === "" ? "" : tr(" Your view: {attitude}.", { attitude })}`;
|
|
512
788
|
}).join("\n")}`);
|
|
513
789
|
if (knowledge !== void 0) {
|
|
514
|
-
const shown = (entries) => entries.slice(0, 30)
|
|
790
|
+
const shown = (entries) => list(entries.slice(0, 30)) + (entries.length > 30 ? tr("; and {count} more you can recall if needed", { count: entries.length - 30 }) : "");
|
|
515
791
|
const lines = [
|
|
516
|
-
knowledge.characters.length === 0 ? void 0 :
|
|
517
|
-
knowledge.factions.length === 0 ? void 0 :
|
|
518
|
-
knowledge.locations.length === 0 ? void 0 :
|
|
519
|
-
knowledge.routes.length === 0 ? void 0 :
|
|
520
|
-
knowledge.items.length === 0 ? void 0 :
|
|
792
|
+
knowledge.characters.length === 0 ? void 0 : `${tr("People: ")}${shown(knowledge.characters)}`,
|
|
793
|
+
knowledge.factions.length === 0 ? void 0 : `${tr("Factions: ")}${shown(knowledge.factions)}`,
|
|
794
|
+
knowledge.locations.length === 0 ? void 0 : `${tr("Places: ")}${shown(knowledge.locations)}`,
|
|
795
|
+
knowledge.routes.length === 0 ? void 0 : `${tr("Routes: ")}${shown(knowledge.routes)}`,
|
|
796
|
+
knowledge.items.length === 0 ? void 0 : `${tr("Things: ")}${shown(knowledge.items)}`
|
|
521
797
|
].filter((line) => line !== void 0);
|
|
522
|
-
if (lines.length > 0) sections.push(
|
|
798
|
+
if (lines.length > 0) sections.push(`${tr("What you know exists (this does not tell you where it is now or what state it is in):")}\n${lines.join("\n")}`);
|
|
523
799
|
}
|
|
524
|
-
if (memories !== void 0 && memories.length > 0) sections.splice(1, 0,
|
|
525
|
-
else if (memories !== void 0) sections.splice(1, 0, "What you remember that bears on this: nothing comes to mind.");
|
|
526
|
-
if (earlier !== void 0 && earlier.length > 0) sections.push(
|
|
800
|
+
if (memories !== void 0 && memories.length > 0) sections.splice(1, 0, `${tr("What you remember that bears on this (only what you took in yourself; do not claim to remember more, and be unsure of what is fuzzy):")}\n${remembered(memories, tr, time?.now)}`);
|
|
801
|
+
else if (memories !== void 0) sections.splice(1, 0, tr("What you remember that bears on this: nothing comes to mind."));
|
|
802
|
+
if (earlier !== void 0 && earlier.length > 0) sections.push(`${tr("Earlier in this scene, before this moment:")}\n${earlier.map((entry) => said(entry, tr)).join("\n")}`);
|
|
527
803
|
if (attempt === 2 && reaction !== void 0) {
|
|
528
|
-
sections.push(
|
|
529
|
-
if (previous !== void 0) sections.push(
|
|
804
|
+
sections.push(`${tr("What just happened, and what you are reacting to:")}\n${reaction.map((entry) => said(entry, tr)).join("\n")}`);
|
|
805
|
+
if (previous !== void 0) sections.push(tr("Your earlier intent did not work out: {intent}\nYou are trying again, knowing the above. Decide again what you do now.", { intent: previous.intent }));
|
|
530
806
|
}
|
|
531
807
|
return {
|
|
532
808
|
persona: [
|
|
533
|
-
describe(member.character),
|
|
809
|
+
describe(member.character, tr),
|
|
534
810
|
request.text("roleplay/character-rules", { name: member.character.name }),
|
|
535
811
|
request.text("roleplay/character-style", { name: member.character.name }),
|
|
536
812
|
...request.lookup ? [request.text("roleplay/character-lookup")] : [],
|
|
@@ -584,7 +860,7 @@ const REMINDED_EVENTS = 5;
|
|
|
584
860
|
* those already folded out of the conversation into the summaries, whose detail the summaries may have lost.
|
|
585
861
|
*/
|
|
586
862
|
/** Where the player is and what is there, who is with them, and who is elsewhere. */
|
|
587
|
-
function placedScene(cast, player, story, describeMember, things) {
|
|
863
|
+
function placedScene(cast, player, story, describeMember, tr, things) {
|
|
588
864
|
const here = player?.place?.location;
|
|
589
865
|
const sections = [];
|
|
590
866
|
if (here !== void 0) {
|
|
@@ -602,45 +878,53 @@ function placedScene(cast, player, story, describeMember, things) {
|
|
|
602
878
|
}];
|
|
603
879
|
})
|
|
604
880
|
};
|
|
605
|
-
sections.push(
|
|
606
|
-
sections.push(
|
|
881
|
+
sections.push(tr("The player's character is in {place}", { place: describePlace(view, { withKeys: true }, tr).join("\n") }));
|
|
882
|
+
sections.push(`${tr("Characters here:")}\n${view.here.map(describeMember).join("\n")}`);
|
|
607
883
|
}
|
|
608
884
|
const elsewhere = cast.filter((member) => member.place !== void 0 && member.place.location.id !== here?.id);
|
|
609
|
-
if (elsewhere.length > 0) sections.push(
|
|
885
|
+
if (elsewhere.length > 0) sections.push(`${tr("Characters elsewhere (they perceive nothing here unless the moment reaches them):")}\n${elsewhere.map((member) => tr("{member} - in {place} ({key})", {
|
|
886
|
+
member: describeMember(member),
|
|
887
|
+
place: member.place.location.name,
|
|
888
|
+
key: locationKey(member.place.location)
|
|
889
|
+
})).join("\n")}`);
|
|
610
890
|
const nowhere = cast.filter((member) => member.place === void 0);
|
|
611
|
-
if (nowhere.length > 0) sections.push(
|
|
891
|
+
if (nowhere.length > 0) sections.push(`${tr("Characters with no place (not part of this scene; they cannot be asked to act):")}\n${nowhere.map(describeMember).join("\n")}`);
|
|
612
892
|
return sections.join("\n\n");
|
|
613
893
|
}
|
|
614
|
-
const castSummary = { scene({ tracked, time, world, cast, turn, input, queryVector, story, items }) {
|
|
894
|
+
const castSummary = { scene({ tracked, time, world, cast, turn, input, queryVector, story, items, language: code }) {
|
|
895
|
+
const language = languageOf(code);
|
|
896
|
+
const tr = translator(language);
|
|
897
|
+
const join = (entries) => entries.join(tr("; "));
|
|
615
898
|
const describeMember = (member) => {
|
|
616
899
|
const { key, character, state } = member;
|
|
617
|
-
const role = character.control === "player" ?
|
|
900
|
+
const role = character.control === "player" ? tr("the player's character, \"{key}\"", { key }) : tr("acts through \"{key}\"", { key });
|
|
618
901
|
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
619
|
-
const where = whereIs(member);
|
|
620
|
-
return `- ${referent(character)} (${role})${where === "" ? "" : ` [${where}]`}${character.summary === "" ? "" :
|
|
902
|
+
const where = whereIs(member, tr);
|
|
903
|
+
return `- ${referent(character)} (${role})${where === "" ? "" : ` [${where}]`}${character.summary === "" ? "" : `${tr(": ")}${character.summary}`}${seen.length > 0 ? ` ${tr("Currently: {state}", { state: join(seen) })}` : ""}`;
|
|
621
904
|
};
|
|
622
905
|
const player = cast.find((member) => member.character.control === "player");
|
|
623
|
-
const days = time?.agenda === void 0 ? "" : describeSceneAgenda(time.agenda, time.now.now);
|
|
906
|
+
const days = time?.agenda === void 0 ? "" : describeSceneAgenda(time.agenda, time.now.now, tr, language);
|
|
907
|
+
const scene = cast.some((member) => member.place !== void 0) ? placedScene(cast, player, story, describeMember, tr, items) : cast.map(describeMember).join("\n");
|
|
624
908
|
const parts = [
|
|
625
|
-
...time === void 0 ? [] : [timeNotice(time)],
|
|
909
|
+
...time === void 0 ? [] : [timeNotice(time, language, tr)],
|
|
626
910
|
...days === "" ? [] : [days],
|
|
627
|
-
|
|
911
|
+
`${tr("Scene before turn {turn}:", { turn })}\n${scene}`
|
|
628
912
|
];
|
|
629
|
-
const activation = describeActivationCandidates(cast, input, story);
|
|
913
|
+
const activation = describeActivationCandidates(cast, input, story, tr);
|
|
630
914
|
if (activation !== "") parts.push(activation);
|
|
631
915
|
if (items !== void 0) {
|
|
632
916
|
const carried = cast.flatMap((member) => {
|
|
633
917
|
const mine = items.carried(member.character.id);
|
|
634
|
-
return mine.length === 0 ? [] : [`- ${member.character.name} (${member.key}): ${describeItems(mine, { withKeys: true })}`];
|
|
918
|
+
return mine.length === 0 ? [] : [`- ${member.character.name} (${member.key}): ${describeItems(mine, { withKeys: true }, tr)}`];
|
|
635
919
|
});
|
|
636
|
-
if (carried.length > 0) parts.push(
|
|
920
|
+
if (carried.length > 0) parts.push(`${tr("What characters have on them:")}\n${carried.join("\n")}`);
|
|
637
921
|
}
|
|
638
|
-
if (world !== void 0 && world.happened.length > 0) parts.push(
|
|
639
|
-
if (world?.upcoming !== void 0 && world.upcoming.length > 0) parts.push(
|
|
640
|
-
if (world !== void 0 && world.beats.length > 0) parts.push(
|
|
641
|
-
if (tracked !== void 0 && tracked.length > 0) parts.push(
|
|
922
|
+
if (world !== void 0 && world.happened.length > 0) parts.push(`${tr("The world acted since the last turn, by itself:")}\n${world.happened.map((line) => `- ${line}`).join("\n")}`);
|
|
923
|
+
if (world?.upcoming !== void 0 && world.upcoming.length > 0) parts.push(`${tr("Known beforehand, still to come (who knows of it; it will happen by itself when its time comes):")}\n${world.upcoming.map((entry) => `- ${entry.text}${entry.when === void 0 ? "" : ` (${entry.when})`} ${tr("[known to {who}]", { who: entry.who })}`).join("\n")}`);
|
|
924
|
+
if (world !== void 0 && world.beats.length > 0) parts.push(`${tr("Weave these into the story when it fits, then say you did with addressed in narrate (each stays for a few turns and is then let go):")}\n${world.beats.map((beat) => `- [${beat.id}] ${beat.text}`).join("\n")}`);
|
|
925
|
+
if (tracked !== void 0 && tracked.length > 0) parts.push(`${tr("What the story keeps track of (change it with variable_changes in an outcome when what happened calls for it):")}\n${tracked.map((line) => `- ${line}`).join("\n")}`);
|
|
642
926
|
const threads = story.threads.list("open");
|
|
643
|
-
if (threads.length > 0) parts.push(
|
|
927
|
+
if (threads.length > 0) parts.push(`${tr("Still open in the story:")}\n${threads.map((thread) => `- ${thread.text}`).join("\n")}`);
|
|
644
928
|
const folded = story.summaries.list().reduce((latest, summary) => Math.max(latest, summary.toTurn), 0);
|
|
645
929
|
if (folded > 0) {
|
|
646
930
|
const mentionedIds = mentioned(input, cast.map(({ character }) => character));
|
|
@@ -657,9 +941,9 @@ const castSummary = { scene({ tracked, time, world, cast, turn, input, queryVect
|
|
|
657
941
|
score: 3 * event.involves.filter((id) => mentionedIds.has(id)).length + overlap(cues, event.text, event.tags)
|
|
658
942
|
})).filter(({ score }) => score >= 2).sort((a, b) => b.score + .5 * b.event.importance - a.score - .5 * a.event.importance || b.event.turn - a.event.turn).map(({ event }) => event);
|
|
659
943
|
const relevant = [...byMeaning, ...byCues].slice(0, REMINDED_EVENTS).sort((a, b) => a.turn - b.turn).map((event) => ({ event }));
|
|
660
|
-
if (relevant.length > 0) parts.push(
|
|
661
|
-
const who = event.involves.map((id) => names.get(id)).filter((name) => name !== void 0).join(", ");
|
|
662
|
-
return `- (turn
|
|
944
|
+
if (relevant.length > 0) parts.push(`${tr("Earlier events that bear on what the player just did (from the records of the story):")}\n${relevant.map(({ event }) => {
|
|
945
|
+
const who = event.involves.map((id) => names.get(id)).filter((name) => name !== void 0).join(tr(", "));
|
|
946
|
+
return `- (${tr("turn {turn}", { turn: event.turn })}) ${event.text}${who === "" ? "" : ` [${who}]`}`;
|
|
663
947
|
}).join("\n")}`);
|
|
664
948
|
}
|
|
665
949
|
return parts.join("\n\n");
|
|
@@ -1538,6 +1822,11 @@ const RESULT = {
|
|
|
1538
1822
|
type: "integer",
|
|
1539
1823
|
description: `From 1 (passing) to 5 (it shapes how they act).`
|
|
1540
1824
|
},
|
|
1825
|
+
confidence: {
|
|
1826
|
+
type: "string",
|
|
1827
|
+
enum: [...MEMORY_CONFIDENCES],
|
|
1828
|
+
description: "How sure they are: doubtful, likely (when you leave it out) or sure, which needs things from at least two different turns."
|
|
1829
|
+
},
|
|
1541
1830
|
perceptions: {
|
|
1542
1831
|
...idList,
|
|
1543
1832
|
description: "The numbers of the things it took in that this rests on."
|
|
@@ -1574,12 +1863,21 @@ const RESULT = {
|
|
|
1574
1863
|
type: "integer",
|
|
1575
1864
|
description: `From 1 to 5.`
|
|
1576
1865
|
},
|
|
1866
|
+
confidence: {
|
|
1867
|
+
type: "string",
|
|
1868
|
+
enum: [...MEMORY_CONFIDENCES],
|
|
1869
|
+
description: "How sure they are now. Raise it only for what supports the belief; lower it only together with contradicted_by."
|
|
1870
|
+
},
|
|
1577
1871
|
perceptions: {
|
|
1578
1872
|
...idList,
|
|
1579
|
-
description: "The numbers of the things it took in since that bear on it."
|
|
1873
|
+
description: "The numbers of the things it took in since that support the belief or bear on it."
|
|
1874
|
+
},
|
|
1875
|
+
contradicted_by: {
|
|
1876
|
+
...idList,
|
|
1877
|
+
description: "The numbers of the things it took in since that speak against the belief; the belief is then doubted, and its confidence must be lowered."
|
|
1580
1878
|
}
|
|
1581
1879
|
},
|
|
1582
|
-
required: ["id"
|
|
1880
|
+
required: ["id"],
|
|
1583
1881
|
additionalProperties: false
|
|
1584
1882
|
}
|
|
1585
1883
|
},
|
|
@@ -1611,75 +1909,143 @@ const RESULT = {
|
|
|
1611
1909
|
],
|
|
1612
1910
|
additionalProperties: false
|
|
1613
1911
|
};
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1912
|
+
function shownOf(session, material) {
|
|
1913
|
+
const turnOf = (perceptionId) => {
|
|
1914
|
+
const seen = session.events.getPerception(perceptionId);
|
|
1915
|
+
return seen === void 0 ? void 0 : session.events.get(seen.eventId)?.turn;
|
|
1916
|
+
};
|
|
1917
|
+
return {
|
|
1918
|
+
perceptions: new Map(material.fresh.map((entry) => [entry.perception.id, entry])),
|
|
1919
|
+
beliefs: new Map(material.beliefs.map((belief) => [belief.id, belief])),
|
|
1920
|
+
supportTurns: new Map(material.beliefs.map((belief) => [belief.id, new Set(session.memories.evidenceOf(belief.id).filter((entry) => entry.relation === "supports").flatMap((entry) => turnOf(entry.perceptionId) ?? []))]))
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
const rankOf = (confidence) => MEMORY_CONFIDENCES.indexOf(confidence);
|
|
1618
1924
|
/**
|
|
1619
1925
|
* Why a proposal cannot be written, or nothing when it can. A belief must rest on what the character took in: on things from at least two
|
|
1620
1926
|
* different turns, or on one event that turned the story; a belief is changed or let go only for what came after it, or for being merged
|
|
1621
1927
|
* into another. Nothing is judged about whether the belief is wise; only whether it is grounded in what the character was given.
|
|
1622
1928
|
*/
|
|
1623
|
-
function proposalProblems(proposal, shown, resolveName) {
|
|
1929
|
+
function proposalProblems(proposal, shown, resolveName, tr = translator("en")) {
|
|
1624
1930
|
const problems = [];
|
|
1625
1931
|
const add = proposal.add ?? [];
|
|
1626
1932
|
const revise = proposal.revise ?? [];
|
|
1627
1933
|
const drop = proposal.drop ?? [];
|
|
1628
|
-
if (add.length > MAX_ADDED) problems.push(
|
|
1629
|
-
if (add.length + revise.length + drop.length > MAX_CHANGES) problems.push(
|
|
1934
|
+
if (add.length > MAX_ADDED) problems.push(tr("add: at most {max} new beliefs in one pass; merge or choose", { max: MAX_ADDED }));
|
|
1935
|
+
if (add.length + revise.length + drop.length > MAX_CHANGES) problems.push(tr("at most {max} changes in one pass", { max: MAX_CHANGES }));
|
|
1630
1936
|
const cited = (ids, where) => (ids ?? []).flatMap((id) => {
|
|
1631
1937
|
const entry = shown.perceptions.get(id);
|
|
1632
|
-
if (entry === void 0) problems.push(
|
|
1938
|
+
if (entry === void 0) problems.push(tr("{where}: there is no thing it took in numbered {id}", {
|
|
1939
|
+
where,
|
|
1940
|
+
id
|
|
1941
|
+
}));
|
|
1633
1942
|
return entry === void 0 ? [] : [entry];
|
|
1634
1943
|
});
|
|
1944
|
+
const known = (value, where) => {
|
|
1945
|
+
const fine = value === void 0 || MEMORY_CONFIDENCES.includes(value);
|
|
1946
|
+
if (!fine) problems.push(tr("{where}: confidence is one of {options}", {
|
|
1947
|
+
where,
|
|
1948
|
+
options: MEMORY_CONFIDENCES.join(", ")
|
|
1949
|
+
}));
|
|
1950
|
+
return fine;
|
|
1951
|
+
};
|
|
1635
1952
|
add.forEach((belief, index) => {
|
|
1636
1953
|
const where = `add[${index}]`;
|
|
1637
|
-
if (!MEMORY_KINDS.includes(belief.kind)) problems.push(
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1954
|
+
if (!MEMORY_KINDS.includes(belief.kind)) problems.push(tr("{where}: unknown kind \"{kind}\"", {
|
|
1955
|
+
where,
|
|
1956
|
+
kind: belief.kind
|
|
1957
|
+
}));
|
|
1958
|
+
if (belief.text.trim() === "") problems.push(tr("{where}: say what it believes", { where }));
|
|
1959
|
+
else if (belief.text.trim().length > MAX_TEXT) problems.push(tr("{where}: at most {max} characters; say it shorter", {
|
|
1960
|
+
where,
|
|
1961
|
+
max: MAX_TEXT
|
|
1962
|
+
}));
|
|
1963
|
+
if (!Number.isInteger(belief.importance) || belief.importance < 1 || belief.importance > 5) problems.push(tr("{where}: importance runs from {min} to {max}", {
|
|
1964
|
+
where,
|
|
1965
|
+
min: 1,
|
|
1966
|
+
max: 5
|
|
1967
|
+
}));
|
|
1968
|
+
const sure = known(belief.confidence, where) && belief.confidence === "sure";
|
|
1641
1969
|
const events = cited(belief.perceptions, where);
|
|
1642
1970
|
const built = (belief.beliefs ?? []).flatMap((id) => {
|
|
1643
|
-
const
|
|
1644
|
-
if (
|
|
1645
|
-
|
|
1971
|
+
const found = shown.beliefs.get(id);
|
|
1972
|
+
if (found === void 0) problems.push(tr("{where}: there is no belief numbered {id}", {
|
|
1973
|
+
where,
|
|
1974
|
+
id
|
|
1975
|
+
}));
|
|
1976
|
+
return found === void 0 ? [] : [found];
|
|
1646
1977
|
});
|
|
1647
|
-
|
|
1648
|
-
|
|
1978
|
+
const turns = /* @__PURE__ */ new Set([...events.map((entry) => entry.event.turn), ...built.map((found) => found.turn)]);
|
|
1979
|
+
if (turns.size < 2 && !events.some((entry) => entry.event.importance >= DECISIVE_IMPORTANCE)) problems.push(tr("{where}: one passing moment is not yet a belief; rest it on things from at least two different turns, or on one event that turned the story", { where }));
|
|
1980
|
+
if (sure && turns.size < 2) problems.push(tr("{where}: to be sure of something it must rest on things from at least two different turns", { where }));
|
|
1981
|
+
for (const name of belief.about ?? []) if (resolveName(name) === void 0) problems.push(tr("{where}: \"{name}\" is not a character; name them as they are named", {
|
|
1982
|
+
where,
|
|
1983
|
+
name
|
|
1984
|
+
}));
|
|
1649
1985
|
});
|
|
1650
1986
|
const touched = /* @__PURE__ */ new Set();
|
|
1651
1987
|
const touch = (id, where) => {
|
|
1652
|
-
if (touched.has(id)) problems.push(
|
|
1988
|
+
if (touched.has(id)) problems.push(tr("{where}: belief {id} is already changed in this pass", {
|
|
1989
|
+
where,
|
|
1990
|
+
id
|
|
1991
|
+
}));
|
|
1653
1992
|
touched.add(id);
|
|
1654
1993
|
};
|
|
1655
1994
|
const fresh = (events, belief, where) => {
|
|
1656
|
-
if (events.length === 0) problems.push(
|
|
1657
|
-
for (const entry of events) if (entry.event.turn < belief.turn) problems.push(
|
|
1995
|
+
if (events.length === 0) problems.push(tr("{where}: say what it took in since that bears on it", { where }));
|
|
1996
|
+
for (const entry of events) if (entry.event.turn < belief.turn) problems.push(tr("{where}: thing {id} came before the belief was formed; cite what came after", {
|
|
1997
|
+
where,
|
|
1998
|
+
id: entry.perception.id
|
|
1999
|
+
}));
|
|
1658
2000
|
};
|
|
1659
2001
|
revise.forEach((change, index) => {
|
|
1660
2002
|
const where = `revise[${index}]`;
|
|
1661
2003
|
const belief = shown.beliefs.get(change.id);
|
|
1662
2004
|
if (belief === void 0) {
|
|
1663
|
-
problems.push(
|
|
2005
|
+
problems.push(tr("{where}: there is no belief numbered {id}", {
|
|
2006
|
+
where,
|
|
2007
|
+
id: change.id
|
|
2008
|
+
}));
|
|
1664
2009
|
return;
|
|
1665
2010
|
}
|
|
1666
2011
|
touch(change.id, where);
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
if (change.
|
|
1670
|
-
|
|
2012
|
+
const supports = cited(change.perceptions, where);
|
|
2013
|
+
const against = cited(change.contradicted_by, where);
|
|
2014
|
+
if (change.text === void 0 && change.importance === void 0 && change.confidence === void 0 && against.length === 0) problems.push(tr("{where}: say what changes", { where }));
|
|
2015
|
+
if (change.text !== void 0 && (change.text.trim() === "" || change.text.trim().length > MAX_TEXT)) problems.push(tr("{where}: the text must be there and at most {max} characters", {
|
|
2016
|
+
where,
|
|
2017
|
+
max: MAX_TEXT
|
|
2018
|
+
}));
|
|
2019
|
+
if (change.importance !== void 0 && (!Number.isInteger(change.importance) || change.importance < 1 || change.importance > 5)) problems.push(tr("{where}: importance runs from {min} to {max}", {
|
|
2020
|
+
where,
|
|
2021
|
+
min: 1,
|
|
2022
|
+
max: 5
|
|
2023
|
+
}));
|
|
2024
|
+
fresh([...supports, ...against], belief, where);
|
|
2025
|
+
if (!known(change.confidence, where) || change.confidence === void 0) {
|
|
2026
|
+
if (against.length > 0) problems.push(tr("{where}: a belief that something contradicts must be doubted: lower its confidence", { where }));
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
if (against.length > 0 && rankOf(change.confidence) >= rankOf(belief.confidence)) problems.push(tr("{where}: a belief that something contradicts must be doubted: lower its confidence", { where }));
|
|
2030
|
+
if (against.length === 0 && rankOf(change.confidence) < rankOf(belief.confidence)) problems.push(tr("{where}: to doubt a belief, name what contradicts it in contradicted_by", { where }));
|
|
2031
|
+
if (change.confidence === "sure" && belief.confidence !== "sure") {
|
|
2032
|
+
if ((/* @__PURE__ */ new Set([...shown.supportTurns?.get(belief.id) ?? [], ...supports.map((entry) => entry.event.turn)])).size < 2) problems.push(tr("{where}: to be sure of something it must rest on things from at least two different turns", { where }));
|
|
2033
|
+
}
|
|
1671
2034
|
});
|
|
1672
2035
|
const dropped = new Set(drop.map((entry) => entry.id));
|
|
1673
2036
|
drop.forEach((change, index) => {
|
|
1674
2037
|
const where = `drop[${index}]`;
|
|
1675
2038
|
const belief = shown.beliefs.get(change.id);
|
|
1676
2039
|
if (belief === void 0) {
|
|
1677
|
-
problems.push(
|
|
2040
|
+
problems.push(tr("{where}: there is no belief numbered {id}", {
|
|
2041
|
+
where,
|
|
2042
|
+
id: change.id
|
|
2043
|
+
}));
|
|
1678
2044
|
return;
|
|
1679
2045
|
}
|
|
1680
2046
|
touch(change.id, where);
|
|
1681
2047
|
if (change.merged_into !== void 0) {
|
|
1682
|
-
if (change.merged_into === change.id || !shown.beliefs.has(change.merged_into) || dropped.has(change.merged_into)) problems.push(
|
|
2048
|
+
if (change.merged_into === change.id || !shown.beliefs.has(change.merged_into) || dropped.has(change.merged_into)) problems.push(tr("{where}: merge into a belief that stays", { where }));
|
|
1683
2049
|
return;
|
|
1684
2050
|
}
|
|
1685
2051
|
fresh(cited(change.perceptions, where), belief, where);
|
|
@@ -1700,34 +2066,50 @@ function editOf(turn, character, proposal, resolveName) {
|
|
|
1700
2066
|
kind: belief.kind,
|
|
1701
2067
|
text: belief.text.trim(),
|
|
1702
2068
|
about: keysOf(belief.about, resolveName),
|
|
1703
|
-
importance: belief.importance
|
|
2069
|
+
importance: belief.importance,
|
|
2070
|
+
...belief.confidence === void 0 ? {} : { confidence: belief.confidence },
|
|
2071
|
+
evidenceFor: belief.perceptions ?? []
|
|
1704
2072
|
})),
|
|
1705
2073
|
beliefEdits: (proposal.revise ?? []).map((change) => ({
|
|
1706
2074
|
id: change.id,
|
|
1707
2075
|
...change.text === void 0 ? {} : { text: change.text.trim() },
|
|
1708
|
-
...change.importance === void 0 ? {} : { importance: change.importance }
|
|
2076
|
+
...change.importance === void 0 ? {} : { importance: change.importance },
|
|
2077
|
+
...change.confidence === void 0 ? {} : { confidence: change.confidence },
|
|
2078
|
+
evidenceFor: change.perceptions ?? [],
|
|
2079
|
+
evidenceAgainst: change.contradicted_by ?? []
|
|
1709
2080
|
})),
|
|
1710
2081
|
beliefRetractions: (proposal.drop ?? []).map((change) => change.id)
|
|
1711
2082
|
};
|
|
1712
2083
|
}
|
|
1713
|
-
function brief(session, material, now, zone, time) {
|
|
2084
|
+
function brief(session, material, now, zone, time, tr) {
|
|
1714
2085
|
const { character, fresh, beliefs } = material;
|
|
1715
2086
|
const named = (id) => session.characters.get(id)?.name ?? String(id);
|
|
2087
|
+
const { disputed } = session.memories.evidenceIndex(character.id);
|
|
1716
2088
|
const believed = beliefs.map((belief) => {
|
|
1717
|
-
const about = belief.about.length === 0 ? "" :
|
|
1718
|
-
|
|
2089
|
+
const about = belief.about.length === 0 ? "" : tr(", about {names}", { names: belief.about.map(named).join(tr(" and ")) });
|
|
2090
|
+
const dispute = disputed.has(belief.id) ? tr(", something taken in since speaks against it") : "";
|
|
2091
|
+
return `- b${belief.id} (${tr("{kind}, importance {importance}, {confidence}{about}{dispute}", {
|
|
2092
|
+
kind: belief.kind,
|
|
2093
|
+
importance: belief.importance,
|
|
2094
|
+
confidence: tr(belief.confidence),
|
|
2095
|
+
about,
|
|
2096
|
+
dispute
|
|
2097
|
+
})}): ${belief.text}`;
|
|
1719
2098
|
});
|
|
1720
2099
|
const taken = fresh.map((entry) => {
|
|
1721
2100
|
const at = time(entry.event.turn, entry.event.round);
|
|
1722
2101
|
return `- p${entry.perception.id}${at === void 0 ? "" : ` (${describeWhen(at, now, zone)})`}: ${entry.perception.content}`;
|
|
1723
2102
|
});
|
|
1724
2103
|
return [
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
2104
|
+
tr("Character: {name}{summary}", {
|
|
2105
|
+
name: referent(character),
|
|
2106
|
+
summary: character.summary === "" ? "" : ` - ${character.summary}`
|
|
2107
|
+
}),
|
|
2108
|
+
tr("What they believe now:"),
|
|
2109
|
+
...believed.length === 0 ? [tr("(nothing yet)")] : believed,
|
|
2110
|
+
tr("What they have taken in since:"),
|
|
1729
2111
|
...taken,
|
|
1730
|
-
"Sort their memory."
|
|
2112
|
+
tr("Sort their memory.")
|
|
1731
2113
|
].join("\n");
|
|
1732
2114
|
}
|
|
1733
2115
|
/**
|
|
@@ -1749,9 +2131,10 @@ function memoryReflector(deps) {
|
|
|
1749
2131
|
const found = session.characters.findByName(name.trim());
|
|
1750
2132
|
return found.length === 1 ? characterKey(found[0]) : void 0;
|
|
1751
2133
|
};
|
|
2134
|
+
const tr = translator(languageOf(settings.prompts.language));
|
|
1752
2135
|
const characters = [];
|
|
1753
2136
|
for (const material of taken) {
|
|
1754
|
-
const shown = shownOf(material);
|
|
2137
|
+
const shown = shownOf(session, material);
|
|
1755
2138
|
const proposal = await runChild({
|
|
1756
2139
|
parent,
|
|
1757
2140
|
signal,
|
|
@@ -1760,11 +2143,12 @@ function memoryReflector(deps) {
|
|
|
1760
2143
|
...childModel(settings, "records"),
|
|
1761
2144
|
trace: childTrace(store, "records", `reflection ${material.character.name}`),
|
|
1762
2145
|
persona: promptFor(parent, "roleplay/reflection", settings.prompts.language),
|
|
1763
|
-
prompt: brief(session, material, now, zone, (turn, round) => session.clock.at(turn, round)),
|
|
2146
|
+
prompt: brief(session, material, now, zone, (turn, round) => session.clock.at(turn, round), tr),
|
|
1764
2147
|
result: RESULT,
|
|
1765
2148
|
beforeSubmit: (value) => {
|
|
1766
|
-
const
|
|
1767
|
-
|
|
2149
|
+
const given = value;
|
|
2150
|
+
const problems = [...proposalProblems(given, shown, resolveName, tr), ...[wrongLanguage(settings.prompts.language, { beliefs: [...given.add ?? [], ...given.revise ?? []].map((belief) => belief.text ?? "").join(" ") })].flatMap((problem) => problem === void 0 ? [] : [problem])];
|
|
2151
|
+
return problems.length === 0 ? void 0 : tr("not acceptable: {problems}", { problems: problems.join("; ") });
|
|
1768
2152
|
},
|
|
1769
2153
|
maxCalls: 3
|
|
1770
2154
|
});
|
|
@@ -1873,6 +2257,6 @@ function deliverNow(session, notes, clock) {
|
|
|
1873
2257
|
}));
|
|
1874
2258
|
}
|
|
1875
2259
|
//#endregion
|
|
1876
|
-
export { readTimeline as A, skipTime as B, notesOfSession as C, observeSurroundings as D, observeAsPlayer as E, beginTurn as F, RESULTS as G, referent as H, describeTime as I, answerEstimate as K, describeWhen as L, defaultBoundaries as M, sameWords as N, TimelineError as O, ClockError as P, endRound as R, clearNotes as S, readNotes as T, AWAY_ACTION_SCHEMA as U, zoneOf as V, CHARACTER_ACTION_SCHEMA as W, plotAuthorNeeded as _, readActivity as a, updatePlotProgress as b, dueReflection as c, reflectionStatus as d, whereabouts as f, pacingAdvice as g, describePacingAdvice as h, keepRunDetail as i, pathTo as j, Timelines as k, memoryReflector as l, addSessionPlot as m, readWithdrawn as n, readRunDetail as o, PLOTS_METADATA_KEY as p, parseCharacterAction as q, forgetRunDetails as r, recordActivity as s, deliverNow as t, recordFailure as u, plotProgressOf as v, putNote as w, addToNote as x, populatePlots as y, readTime as z };
|
|
2260
|
+
export { readTimeline as A, skipTime as B, notesOfSession as C, observeSurroundings as D, observeAsPlayer as E, beginTurn as F, RESULTS as G, referent as H, describeTime as I, languageOf as J, answerEstimate as K, describeWhen as L, defaultBoundaries as M, sameWords as N, TimelineError as O, ClockError as P, endRound as R, clearNotes as S, readNotes as T, AWAY_ACTION_SCHEMA as U, zoneOf as V, CHARACTER_ACTION_SCHEMA as W, translator as Y, plotAuthorNeeded as _, readActivity as a, updatePlotProgress as b, dueReflection as c, reflectionStatus as d, whereabouts as f, pacingAdvice as g, describePacingAdvice as h, keepRunDetail as i, pathTo as j, Timelines as k, memoryReflector as l, addSessionPlot as m, readWithdrawn as n, readRunDetail as o, PLOTS_METADATA_KEY as p, parseCharacterAction as q, forgetRunDetails as r, recordActivity as s, deliverNow as t, recordFailure as u, plotProgressOf as v, putNote as w, addToNote as x, populatePlots as y, readTime as z };
|
|
1877
2261
|
|
|
1878
|
-
//# sourceMappingURL=deliver
|
|
2262
|
+
//# sourceMappingURL=deliver-BDW5WZvc.js.map
|