@dsh-agentic-roleplay/core 0.3.1 → 0.3.2
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 +2 -2
- package/lib/client.js +1299 -375
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/{deliver-BDW5WZvc.js → deliver-BSsDtF6X.js} +1198 -17
- package/lib/{documents-DtlY2IRt.js → documents-B5XAdfo2.js} +141 -8
- package/lib/{gallery-DACG5eh2.js → gallery-DS5-qH9F.js} +2 -2
- package/lib/{generator-DGYcLMp7.js → generator-BzeepLd2.js} +2 -2
- package/lib/images.js +3 -3
- package/lib/index.js +178 -10
- package/lib/narration-DK2kiIjE.js +141 -0
- package/lib/orchestration.js +684 -1456
- package/lib/{packs-CkRZDCsV.js → packs-BCGK9KZV.js} +3 -3
- package/lib/{presenter-agent-PK9JYExk.js → presenter-agent-Cp-J0onD.js} +3 -3
- package/lib/{narration-5ig7Dg28.js → settings-CA6icLL_.js} +156 -141
- package/package.json +2 -2
- package/prompts/en/roleplay/dice.md +7 -0
- package/prompts/en/roleplay/game-master.md +2 -0
- package/prompts/en/roleplay/reflection.md +3 -1
- package/prompts/zh/roleplay/dice.md +7 -0
- package/prompts/zh/roleplay/game-master.md +2 -0
- package/prompts/zh/roleplay/reflection.md +3 -1
- package/lib/src-CWTNeL6Y.js +0 -128
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { K as SessionNotFoundError, P as inheritPrompts, S as wrongLanguage, i as inheritPacks } from "./packs-
|
|
3
|
-
import "./
|
|
4
|
-
import {
|
|
2
|
+
import { K as SessionNotFoundError, P as inheritPrompts, S as wrongLanguage, T as parsePlotsFile, i as inheritPacks } from "./packs-BCGK9KZV.js";
|
|
3
|
+
import "./settings-CA6icLL_.js";
|
|
4
|
+
import { n as encodeOutput, r as encodePreview } from "./narration-DK2kiIjE.js";
|
|
5
|
+
import { A as runChild, D as childSampling, E as childModel, j as estimateAnswer, k as childTrace, u as inheritImages } from "./generator-BzeepLd2.js";
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7
8
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
8
|
-
import {
|
|
9
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
10
|
+
import { DAY, ITEM_ACTIONS, MINUTE, SECOND, addLocalDays, characterKey, clockTime, createCharacterTools, createDiceTools, createTools, dayPart, describeDuration, describeInstant, holidaysOn, isSessionId, localTime, locationKey, mentioned, nextTimeOfDay, overlap, readCalendar, seasonOf, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
|
|
9
11
|
//#region ../dsh-roleplay-model/src/memory.ts
|
|
10
12
|
const MEMORY_KINDS = [
|
|
11
13
|
"belief",
|
|
@@ -52,6 +54,16 @@ const ZH = {
|
|
|
52
54
|
"age: {value}": "年龄:{value}",
|
|
53
55
|
"gender: {value}": "性别:{value}",
|
|
54
56
|
"pronouns: {value}": "代词:{value}",
|
|
57
|
+
"- {key} ({name}): {use}": "- {key}({name}):{use}",
|
|
58
|
+
"Rolls {dice}.": "掷 {dice}。",
|
|
59
|
+
"Give a target: the difficulty, the number to meet or beat; set it by how hard the attempt is.": "需给出 target:难度,即要达到或超过的数字;按这次尝试的难易来定。",
|
|
60
|
+
"Give a target: the number to stay under; set it by how hard the attempt is.": "需给出 target:要低于的数字;按这次尝试的难易来定。",
|
|
61
|
+
"It adds the character's {variable}.": "它会加上该角色的 {variable}。",
|
|
62
|
+
"Counts the dice that show {hit} or more.": "统计显示 {hit} 或更高的骰子数。",
|
|
63
|
+
"the player's roll": "玩家的掷骰",
|
|
64
|
+
"The player rolled {dice} ({reason}) and got {total}: dice {faces}. This is a fact, decided by the dice: take it into account when you judge the attempt and decide what happens.": "玩家掷了 {dice}({reason}),得到 {total}:骰面 {faces}。这是由骰子决定的事实:在你判断这次尝试、决定发生什么时把它考虑进去。",
|
|
65
|
+
"The checks of this story:": "本故事的检定:",
|
|
66
|
+
"No checks are defined: use roll_dice only.": "没有定义检定:只用 roll_dice。",
|
|
55
67
|
"Situation:": "当前情形:",
|
|
56
68
|
"Now: {time}.": "现在是:{time}。",
|
|
57
69
|
"Where you are:": "你所在之处:",
|
|
@@ -149,7 +161,9 @@ const ZH = {
|
|
|
149
161
|
"{where}: say what it took in since that bears on it": "{where}:请写出此后与之相关的经历",
|
|
150
162
|
"{where}: thing {id} came before the belief was formed; cite what came after": "{where}:经历 {id} 发生在看法形成之前;请引用之后发生的事",
|
|
151
163
|
"{where}: say what changes": "{where}:请写出有何改变",
|
|
152
|
-
"{where}: the text must be there and at most {max} characters": "{where}
|
|
164
|
+
"{where}: the text must be there and at most {max} characters; leave it out to keep the belief as it is": "{where}:文字不能为空,且最多 {max} 个字符;想保持信念原样就不要写这一项",
|
|
165
|
+
"{where}: the confidence, the importance and the numbers are fields of their own, not part of the text": "{where}:把握程度、重要性和编号是各自独立的字段,不属于文字",
|
|
166
|
+
"{where}: name what speaks against the belief in contradicted_by": "{where}:在 contradicted_by 里写出与该信念相悖的内容的编号",
|
|
153
167
|
"{where}: a belief that something contradicts must be doubted: lower its confidence": "{where}:被事实相悖的看法必须存疑:请降低其 confidence",
|
|
154
168
|
"{where}: to doubt a belief, name what contradicts it in contradicted_by": "{where}:要对看法存疑,请在 contradicted_by 中写明与之相悖的经历",
|
|
155
169
|
"{where}: merge into a belief that stays": "{where}:请合并到保留的看法中",
|
|
@@ -202,7 +216,9 @@ const ZH = {
|
|
|
202
216
|
"The time you had for \"{goal}\" has passed ({when}; it is {now} now)": "你为“{goal}”预留的时间已过({when};现在是{now})",
|
|
203
217
|
"You are not with the player's character and nothing of this happens in front of anyone: decide what you do about it.": "你不和玩家的角色在一起,这件事也不会发生在任何人面前:决定你要怎么处理。",
|
|
204
218
|
"{names} noticed: {text}": "{names}注意到:{text}",
|
|
205
|
-
"{name} went to {place}.": "{name}去了{place}。"
|
|
219
|
+
"{name} went to {place}.": "{name}去了{place}。",
|
|
220
|
+
"## MCP resource servers\n\nUse {tools} with the server argument naming an MCP server.": "## MCP 资源服务器\n\n使用 {tools},server 参数填 MCP 服务器的名称。",
|
|
221
|
+
"## MCP resource servers\n\nUse {tools} with one of these names as the server argument: {servers}.": "## MCP 资源服务器\n\n使用 {tools},server 参数填下列名称之一:{servers}。"
|
|
206
222
|
};
|
|
207
223
|
//#endregion
|
|
208
224
|
//#region ../dsh-roleplay-model/src/messages.ts
|
|
@@ -1565,6 +1581,122 @@ function notesOfSession(deps, id) {
|
|
|
1565
1581
|
return readNotes(deps.open(id));
|
|
1566
1582
|
}
|
|
1567
1583
|
//#endregion
|
|
1584
|
+
//#region src/shared/ooc.ts
|
|
1585
|
+
/** What the player writes to speak to the game master as the author of the story: a command (`/ooc`) or a question (`/ask`), a turn of its own, never mixed with an action of the character. */
|
|
1586
|
+
const OOC_COMMAND = /^\s*\/(ooc|ask)(?=\s|$)\s*([\s\S]*)$/i;
|
|
1587
|
+
/** The command or question in a player's message, or nothing when the message is an ordinary action. The request may be empty. */
|
|
1588
|
+
function parseOoc(text) {
|
|
1589
|
+
const match = OOC_COMMAND.exec(text);
|
|
1590
|
+
return match === null ? void 0 : {
|
|
1591
|
+
request: (match[2] ?? "").trim(),
|
|
1592
|
+
question: match[1].toLowerCase() === "ask"
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
/** The longest answer to an out-of-character question. */
|
|
1596
|
+
const MAX_OOC_ANSWER = 1200;
|
|
1597
|
+
//#endregion
|
|
1598
|
+
//#region src/host/orchestration/character-runner.ts
|
|
1599
|
+
/**
|
|
1600
|
+
* Runs each character as a one-shot child of the game master. It is the character and nothing
|
|
1601
|
+
* else: it knows what its brief gives it, and its only tool (when the chat allows it) reaches
|
|
1602
|
+
* the memory of that character alone, so characters acting at the same time cannot see each
|
|
1603
|
+
* other's memories.
|
|
1604
|
+
*/
|
|
1605
|
+
function characterRunner(deps) {
|
|
1606
|
+
return async (request, signal) => {
|
|
1607
|
+
const brief = deps.boundaries().characterContext.brief(request);
|
|
1608
|
+
const tools = request.lookup ? createCharacterTools(() => ({
|
|
1609
|
+
session: deps.store.story,
|
|
1610
|
+
turn: request.turn,
|
|
1611
|
+
policy: deps.store.settings().memory,
|
|
1612
|
+
queryVector: deps.store.queryVector
|
|
1613
|
+
}), request.member.character.id) : [];
|
|
1614
|
+
const settings = deps.store.settings();
|
|
1615
|
+
const external = externalGiven(deps.parent.ctx.tools, settings.tools, "characters");
|
|
1616
|
+
const named = request.member.character.tier === "background" && settings.models.background.trim() !== "" ? settings.models.background : settings.models.characters;
|
|
1617
|
+
return parseCharacterAction(await runChild({
|
|
1618
|
+
parent: deps.parent,
|
|
1619
|
+
signal,
|
|
1620
|
+
sampling: childSampling(settings, "characters", answerEstimate(settings.prompts.language, request.away === true)),
|
|
1621
|
+
...childModel(settings, "characters", named),
|
|
1622
|
+
trace: childTrace(deps.store, "characters", request.member.character.name, recalledOf(request), named),
|
|
1623
|
+
reasoningEffort: deps.store.settings().reasoning.children,
|
|
1624
|
+
persona: brief.persona,
|
|
1625
|
+
prompt: brief.prompt,
|
|
1626
|
+
tools,
|
|
1627
|
+
external,
|
|
1628
|
+
maxCalls: deps.store.settings().memory.lookupCalls + (external.length === 0 ? 0 : EXTERNAL_CALLS),
|
|
1629
|
+
result: request.away === true ? AWAY_ACTION_SCHEMA : CHARACTER_ACTION_SCHEMA,
|
|
1630
|
+
unenforced: ["thought"],
|
|
1631
|
+
beforeSubmit: (value) => spokenIn(settings.prompts.language, value)
|
|
1632
|
+
}));
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
/** What a character that was given tools of other plugins may call on top of its memory look-ups. */
|
|
1636
|
+
const EXTERNAL_CALLS = 5;
|
|
1637
|
+
/** A character whose sheet is in another language than the chat's writes in the sheet's: the answer is refused until it is in the chat's. */
|
|
1638
|
+
function spokenIn(language, value) {
|
|
1639
|
+
const given = value;
|
|
1640
|
+
return wrongLanguage(language, {
|
|
1641
|
+
thought: given.thought,
|
|
1642
|
+
intent: given.intent,
|
|
1643
|
+
utterance: given.utterance,
|
|
1644
|
+
account: given.account
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
/** What the character was reminded of and why, for the run's record, when the recall said why. */
|
|
1648
|
+
function recalledOf(request) {
|
|
1649
|
+
const explained = (request.memories ?? []).filter((memory) => memory.why !== void 0);
|
|
1650
|
+
return explained.length === 0 ? {} : { recalled: explained.slice(0, 30).map(({ clarity, turn, text, why }) => ({
|
|
1651
|
+
clarity,
|
|
1652
|
+
turn,
|
|
1653
|
+
text,
|
|
1654
|
+
why
|
|
1655
|
+
})) };
|
|
1656
|
+
}
|
|
1657
|
+
const ANSWER_SCHEMA = {
|
|
1658
|
+
type: "object",
|
|
1659
|
+
properties: { answer: {
|
|
1660
|
+
type: "string",
|
|
1661
|
+
description: "The answer to the player, in plain words, in a few sentences."
|
|
1662
|
+
} },
|
|
1663
|
+
required: ["answer"],
|
|
1664
|
+
additionalProperties: false
|
|
1665
|
+
};
|
|
1666
|
+
/**
|
|
1667
|
+
* Answers a player's question as an agent that has only what the player's character is given when it acts: the character sheet is left out and nothing the
|
|
1668
|
+
* game master alone knows is in the prompt, so the answer cannot give away what the character could not know.
|
|
1669
|
+
*/
|
|
1670
|
+
function answerRunner(deps) {
|
|
1671
|
+
return async (request, signal) => {
|
|
1672
|
+
const brief = deps.boundaries().characterContext.brief(request);
|
|
1673
|
+
return (await runChild({
|
|
1674
|
+
parent: deps.parent,
|
|
1675
|
+
signal,
|
|
1676
|
+
sampling: childSampling(deps.store.settings(), "records", estimateAnswer([MAX_OOC_ANSWER], deps.store.settings().prompts.language)),
|
|
1677
|
+
...childModel(deps.store.settings(), "records"),
|
|
1678
|
+
trace: childTrace(deps.store, "records", "answer to the player"),
|
|
1679
|
+
reasoningEffort: deps.store.settings().reasoning.children,
|
|
1680
|
+
persona: request.text("roleplay/ask-answerer", { name: request.member.character.name }),
|
|
1681
|
+
prompt: brief.prompt,
|
|
1682
|
+
tools: [],
|
|
1683
|
+
maxCalls: 3,
|
|
1684
|
+
result: ANSWER_SCHEMA
|
|
1685
|
+
})).answer;
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
//#endregion
|
|
1689
|
+
//#region src/host/orchestration/boundaries.ts
|
|
1690
|
+
/** Why the game master may ask for something to be made up: the story genuinely needs it. */
|
|
1691
|
+
const AUTHORING_NEEDS = [
|
|
1692
|
+
"scene_change",
|
|
1693
|
+
"arrival",
|
|
1694
|
+
"introduction",
|
|
1695
|
+
"object",
|
|
1696
|
+
"variable",
|
|
1697
|
+
"trigger"
|
|
1698
|
+
];
|
|
1699
|
+
//#endregion
|
|
1568
1700
|
//#region src/host/pacing/director.ts
|
|
1569
1701
|
const PLOTS_METADATA_KEY = "roleplay.pacing.plots";
|
|
1570
1702
|
function populatePlots(metadata, plots) {
|
|
@@ -1661,6 +1793,997 @@ function updatePlotProgress(store, plotId, developmentId, action) {
|
|
|
1661
1793
|
return progress;
|
|
1662
1794
|
}
|
|
1663
1795
|
//#endregion
|
|
1796
|
+
//#region src/host/pacing/author.ts
|
|
1797
|
+
const RESULT$1 = {
|
|
1798
|
+
type: "object",
|
|
1799
|
+
required: [
|
|
1800
|
+
"id",
|
|
1801
|
+
"name",
|
|
1802
|
+
"premise",
|
|
1803
|
+
"themes",
|
|
1804
|
+
"hook",
|
|
1805
|
+
"developments",
|
|
1806
|
+
"stakes",
|
|
1807
|
+
"resolutions",
|
|
1808
|
+
"participants"
|
|
1809
|
+
],
|
|
1810
|
+
additionalProperties: false,
|
|
1811
|
+
properties: {
|
|
1812
|
+
id: { type: "string" },
|
|
1813
|
+
name: { type: "string" },
|
|
1814
|
+
premise: { type: "string" },
|
|
1815
|
+
themes: {
|
|
1816
|
+
type: "array",
|
|
1817
|
+
items: { type: "string" }
|
|
1818
|
+
},
|
|
1819
|
+
hook: {
|
|
1820
|
+
type: "object",
|
|
1821
|
+
required: [
|
|
1822
|
+
"id",
|
|
1823
|
+
"text",
|
|
1824
|
+
"guidance",
|
|
1825
|
+
"avoid"
|
|
1826
|
+
],
|
|
1827
|
+
additionalProperties: false,
|
|
1828
|
+
properties: {
|
|
1829
|
+
id: { type: "string" },
|
|
1830
|
+
text: { type: "string" },
|
|
1831
|
+
guidance: { type: "string" },
|
|
1832
|
+
avoid: {
|
|
1833
|
+
type: "array",
|
|
1834
|
+
items: { type: "string" }
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
},
|
|
1838
|
+
developments: {
|
|
1839
|
+
type: "array",
|
|
1840
|
+
items: {
|
|
1841
|
+
type: "object",
|
|
1842
|
+
required: [
|
|
1843
|
+
"id",
|
|
1844
|
+
"text",
|
|
1845
|
+
"mode",
|
|
1846
|
+
"prerequisites",
|
|
1847
|
+
"guidance",
|
|
1848
|
+
"avoid"
|
|
1849
|
+
],
|
|
1850
|
+
additionalProperties: false,
|
|
1851
|
+
properties: {
|
|
1852
|
+
id: { type: "string" },
|
|
1853
|
+
text: { type: "string" },
|
|
1854
|
+
mode: {
|
|
1855
|
+
type: "string",
|
|
1856
|
+
enum: [
|
|
1857
|
+
"opportunity",
|
|
1858
|
+
"reminder",
|
|
1859
|
+
"character",
|
|
1860
|
+
"consequence",
|
|
1861
|
+
"escalation",
|
|
1862
|
+
"breathing_room"
|
|
1863
|
+
]
|
|
1864
|
+
},
|
|
1865
|
+
prerequisites: {
|
|
1866
|
+
type: "array",
|
|
1867
|
+
items: { type: "string" }
|
|
1868
|
+
},
|
|
1869
|
+
guidance: { type: "string" },
|
|
1870
|
+
avoid: {
|
|
1871
|
+
type: "array",
|
|
1872
|
+
items: { type: "string" }
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
},
|
|
1877
|
+
stakes: {
|
|
1878
|
+
type: "array",
|
|
1879
|
+
items: { type: "string" }
|
|
1880
|
+
},
|
|
1881
|
+
resolutions: {
|
|
1882
|
+
type: "array",
|
|
1883
|
+
items: { type: "string" }
|
|
1884
|
+
},
|
|
1885
|
+
participants: {
|
|
1886
|
+
type: "array",
|
|
1887
|
+
items: { type: "string" }
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
/** A scaffold is about two dozen short texts: premise, hook, developments with their guidance, stakes and resolutions. */
|
|
1892
|
+
const PLOT_TEXTS = 24;
|
|
1893
|
+
const PLOT_TEXT_CHARS = 300;
|
|
1894
|
+
async function authorPlot(parent, store, turn, signal) {
|
|
1895
|
+
const cast = store.cast().map((member) => `${member.character.name} (${member.key}): ${member.character.summary}`).join("\n");
|
|
1896
|
+
const factions = store.story.factions.list().map((faction) => `${faction.name} (${faction.sourceId ?? faction.id}): ${faction.summary}`).join("\n");
|
|
1897
|
+
const places = store.story.locations.list().map((place) => `${place.name} (${place.sourceId ?? place.id})`).join(", ");
|
|
1898
|
+
const events = store.story.events.list().slice(-12).map((event) => `- ${event.text}`).join("\n");
|
|
1899
|
+
let checked;
|
|
1900
|
+
const result = await runChild({
|
|
1901
|
+
parent,
|
|
1902
|
+
signal,
|
|
1903
|
+
sampling: childSampling(store.settings(), "authoring", estimateAnswer(Array.from({ length: PLOT_TEXTS }, () => PLOT_TEXT_CHARS), store.settings().prompts.language)),
|
|
1904
|
+
...childModel(store.settings(), "authoring"),
|
|
1905
|
+
trace: childTrace(store, "authoring", "plot author"),
|
|
1906
|
+
persona: promptFor(parent, "roleplay/plot-author", store.settings().prompts.language),
|
|
1907
|
+
reasoningEffort: store.settings().reasoning.children,
|
|
1908
|
+
result: RESULT$1,
|
|
1909
|
+
maxCalls: 3,
|
|
1910
|
+
prompt: `The story has gone quiet by turn ${turn}. Propose one optional plot scaffold that grows from this state.\n\nCharacters:\n${cast || "- none"}\n\nFactions:\n${factions || "- none"}\n\nPlaces: ${places || "none"}\n\nRecent recorded events:\n${events || "- none"}`,
|
|
1911
|
+
beforeSubmit(value) {
|
|
1912
|
+
const authored = value;
|
|
1913
|
+
const candidate = {
|
|
1914
|
+
...authored,
|
|
1915
|
+
hooks: [{
|
|
1916
|
+
...authored.hook,
|
|
1917
|
+
mode: "opportunity",
|
|
1918
|
+
prerequisites: []
|
|
1919
|
+
}],
|
|
1920
|
+
start: "available",
|
|
1921
|
+
pacing: {
|
|
1922
|
+
quietTurns: 3,
|
|
1923
|
+
cooldownTurns: 4,
|
|
1924
|
+
cooldownDays: 1
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
const parsed = parsePlotsFile(JSON.stringify([candidate]));
|
|
1928
|
+
if (!parsed.ok) return parsed.issues.map((issue) => `${issue.path}: ${issue.message}`).join("\n");
|
|
1929
|
+
checked = parsed.value[0];
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
if (checked === void 0) throw new Error(`the plot author returned an invalid plot: ${result.name}`);
|
|
1933
|
+
addSessionPlot(store, checked);
|
|
1934
|
+
return checked;
|
|
1935
|
+
}
|
|
1936
|
+
//#endregion
|
|
1937
|
+
//#region src/host/orchestration/tools.ts
|
|
1938
|
+
const ACTIVATE_TOOL = "activate_characters";
|
|
1939
|
+
const RESOLVE_TOOL = "resolve_round";
|
|
1940
|
+
const NARRATE_TOOL = "narrate";
|
|
1941
|
+
const RECORD_TOOL = "record_memory";
|
|
1942
|
+
const EXPAND_TOOL = "expand_world";
|
|
1943
|
+
const INTRODUCE_TOOL = "introduce_thing";
|
|
1944
|
+
const TIME_TOOL = "advance_time";
|
|
1945
|
+
const PREVIEW_TOOL = "preview_scene";
|
|
1946
|
+
const RULING_TOOL = "ooc_ruling";
|
|
1947
|
+
const ANSWER_TOOL = "ooc_answer";
|
|
1948
|
+
const JUDGE_TOOL = "judge_action";
|
|
1949
|
+
const PLOT_TOOL = "record_plot_progress";
|
|
1950
|
+
const AUTHOR_PLOT_TOOL = "author_plot";
|
|
1951
|
+
/** The JSON value the tool records; the model reads the rendered text. */
|
|
1952
|
+
function record(value) {
|
|
1953
|
+
return JSON.parse(JSON.stringify(value));
|
|
1954
|
+
}
|
|
1955
|
+
function failures(list) {
|
|
1956
|
+
return list.length === 0 ? [] : [
|
|
1957
|
+
"",
|
|
1958
|
+
"Could not act:",
|
|
1959
|
+
...list.map((failure) => failure.technical === true ? `- ${failure.character} (${failure.name}): no decision came back. That is a fault of the system, not something that happened in the story: nothing is recorded for ${failure.name} this round, so write nothing for them and say nothing about why` : `- ${failure.character} (${failure.name}): ${failure.reason}`)
|
|
1960
|
+
];
|
|
1961
|
+
}
|
|
1962
|
+
function renderAttempt(attempt) {
|
|
1963
|
+
const heading = attempt.attempt === 1 ? "The characters acted. Their intents may conflict with each other; you decide what actually happens." : "These characters failed but were highly committed, so each tried once more, knowing what just happened.";
|
|
1964
|
+
const lines = attempt.reports.map((report) => `- ${report.character} (${report.name}): ${report.utterance === void 0 ? "says nothing" : `says "${report.utterance}"`}; does: ${report.intent} [commitment: ${report.commitment}]`);
|
|
1965
|
+
const next = attempt.reports.length === 0 ? ["", "Nobody could act. Fix the problem or call activate_characters again with a different set."] : attempt.attempt === 1 ? ["", `Now call ${RESOLVE_TOOL} with one outcome for each of: ${attempt.reports.map((report) => report.character).join(", ")}.`] : ["", `Call ${RESOLVE_TOOL} once more with one outcome for each of: ${attempt.reports.map((report) => report.character).join(", ")}. There are no further retries: what you decide now is final.`];
|
|
1966
|
+
return [
|
|
1967
|
+
heading,
|
|
1968
|
+
...lines,
|
|
1969
|
+
...failures(attempt.failures),
|
|
1970
|
+
...next
|
|
1971
|
+
].join("\n");
|
|
1972
|
+
}
|
|
1973
|
+
/** Who went where because their day says so. */
|
|
1974
|
+
const routineLine = (move) => `By their routine, ${move.name} is now at ${move.to} (${move.activity}).`;
|
|
1975
|
+
const OUTPUT_RULES = "Deliver the output with the narrate tool as ordered segments: utterances and narration. Narration may come before, between and after utterances and is yours to write. Utterances are the characters' words: include every one exactly as given, once, in the order they were spoken, and never change, add or remove one.";
|
|
1976
|
+
const listed = (utterances) => utterances.map((utterance) => `- ${utterance.character} (${utterance.name}), round ${utterance.round}: "${utterance.text}"`).join("\n");
|
|
1977
|
+
/** What the world did by itself, as the game master is told: what happened, what characters notice, and what it is to weave in. */
|
|
1978
|
+
function renderWorld(world) {
|
|
1979
|
+
return world.flatMap((entry) => [
|
|
1980
|
+
...entry.events.map((text) => `The world acted (${entry.name}): ${text}`),
|
|
1981
|
+
...entry.cues.map((cue) => `${cue.names.join(" and ")} will notice: ${cue.text}`),
|
|
1982
|
+
...entry.beats.map((beat) => `Weave this into the story, then say you did with addressed: [${beat.id}] in narrate (${beat.text})`)
|
|
1983
|
+
]);
|
|
1984
|
+
}
|
|
1985
|
+
function renderResolution(report) {
|
|
1986
|
+
if (report.next !== void 0) return renderAttempt(report.next);
|
|
1987
|
+
const done = report.done;
|
|
1988
|
+
if (done === void 0) return "";
|
|
1989
|
+
const left = done.limit - done.round;
|
|
1990
|
+
const passed = done.time.to - done.time.from;
|
|
1991
|
+
const lines = [
|
|
1992
|
+
`Round ${done.round} is recorded (${done.updated.join(", ")}).`,
|
|
1993
|
+
`It is now ${describeTime({
|
|
1994
|
+
now: done.time.to,
|
|
1995
|
+
zone: done.time.zone
|
|
1996
|
+
})}${passed > 0 ? `; ${describeDuration(passed)} passed` : ""}.`,
|
|
1997
|
+
...done.moved.map(routineLine),
|
|
1998
|
+
...done.moves.map((move) => `${move.name} is now at ${move.to}${move.via > 0 ? ` (by way of ${move.via} other place${move.via === 1 ? "" : "s"})` : ""}.`),
|
|
1999
|
+
...done.things.map((thing) => `${thing.name}: ${thing.summary}.`),
|
|
2000
|
+
...done.variables.map((line) => `${line}.`),
|
|
2001
|
+
...renderWorld(done.world),
|
|
2002
|
+
...failures(done.retryFailures)
|
|
2003
|
+
];
|
|
2004
|
+
lines.push(done.spoken.length === 0 ? "Nobody has said anything yet this turn." : `Everything said so far this turn, in order; the output must carry all of it exactly:\n${listed(done.spoken)}`);
|
|
2005
|
+
lines.push(left > 0 ? `Now decide. If the story genuinely flows from what just happened (someone is directly answered, a reaction is natural, something is left unresolved that the characters would act on), call activate_characters for the next round: ${left} round(s) are left for this message. Otherwise give control back to the player now.` : "That was the last round allowed for this message: give control back to the player now.");
|
|
2006
|
+
lines.push(done.waiting === 0 ? "Nothing is waiting to be recorded." : `${done.waiting} round${done.waiting === 1 ? " is" : "s are"} waiting to be recorded in the story's memory. Memory is not written after every round: call ${RECORD_TOOL} when the story just moved on (a decision made, a secret or fact revealed, a promise, an injury, a relationship changed, the scene or time moved); skip it for small talk and routine movement, which are kept and recorded together with the next thing that matters.`);
|
|
2007
|
+
lines.push(OUTPUT_RULES);
|
|
2008
|
+
lines.push("Narrate only what the player's character can perceive.");
|
|
2009
|
+
return lines.join("\n");
|
|
2010
|
+
}
|
|
2011
|
+
function renderExpansion(report) {
|
|
2012
|
+
if (report.created.length === 0) return `Nothing was made up: ${(report.declined ?? "the world author found nothing the story needs").replace(/[.\s]+$/, "")}. Work with what exists.`;
|
|
2013
|
+
const lines = report.created.map((entry) => `- ${entry.kind} ${entry.key} (${entry.name})`);
|
|
2014
|
+
const characters = report.created.filter((entry) => entry.kind === "character");
|
|
2015
|
+
return [
|
|
2016
|
+
"Made up and fitted into the world:",
|
|
2017
|
+
...lines,
|
|
2018
|
+
...characters.length === 0 ? [] : [`${characters.length === 1 ? "They are" : "They are all"} now in the cast: ask them to act with ${ACTIVATE_TOOL}, by their keys, like anyone else.`],
|
|
2019
|
+
...report.declined === void 0 ? [] : [`Not made: ${report.declined}`]
|
|
2020
|
+
].join("\n");
|
|
2021
|
+
}
|
|
2022
|
+
/** The tools the game master plays a turn with. */
|
|
2023
|
+
function createTools$1(deps) {
|
|
2024
|
+
const ownerOf = (agent) => {
|
|
2025
|
+
if (agent === void 0) throw new Error("the roleplay tools can only be called by an agent");
|
|
2026
|
+
return {
|
|
2027
|
+
agent,
|
|
2028
|
+
owner: {
|
|
2029
|
+
chat: agent.session.id,
|
|
2030
|
+
turn: deps.turnOf(agent)
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
};
|
|
2034
|
+
const storeOf = (chat) => {
|
|
2035
|
+
const store = deps.stores(chat);
|
|
2036
|
+
if (store === void 0) throw new Error("this chat is not a roleplay session");
|
|
2037
|
+
return store;
|
|
2038
|
+
};
|
|
2039
|
+
const activate = defineTool({
|
|
2040
|
+
name: ACTIVATE_TOOL,
|
|
2041
|
+
description: "Let the characters act: one round of the turn. Each character asked is asked, separately and at the same time, what it intends to do and say in the situation you describe and how committed it is. Call it after reading what the player did, and again for a later round only when the story genuinely needs the characters to react to what just happened; the number of rounds for one player message is limited.",
|
|
2042
|
+
parameters: {
|
|
2043
|
+
characters: {
|
|
2044
|
+
type: "array",
|
|
2045
|
+
required: true,
|
|
2046
|
+
items: { type: "string" },
|
|
2047
|
+
description: "Keys of the characters to ask, chosen by you from the scene (where each is, what each is doing). Ask only those the moment reaches: those in the same place, and those elsewhere who can plainly see, hear or are summoned; a character elsewhere perceives nothing by itself. Never the whole cast. In a later round ask only those the moment calls for."
|
|
2048
|
+
},
|
|
2049
|
+
situation: {
|
|
2050
|
+
type: "string",
|
|
2051
|
+
required: true,
|
|
2052
|
+
description: "An objective description of the moment: in the first round what the player's character just did or said; in a later round what is happening now, following from the rounds before (they are told those too). Every character is told this and nothing more, so leave out anyone's private thoughts."
|
|
2053
|
+
}
|
|
2054
|
+
},
|
|
2055
|
+
output: {
|
|
2056
|
+
schema: { type: "json" },
|
|
2057
|
+
render: (_args, value) => [{
|
|
2058
|
+
type: "text",
|
|
2059
|
+
text: renderAttempt(value)
|
|
2060
|
+
}]
|
|
2061
|
+
},
|
|
2062
|
+
isConcurrencySafe: () => false,
|
|
2063
|
+
async execute(args, exec) {
|
|
2064
|
+
const { agent, owner } = ownerOf(exec.agent);
|
|
2065
|
+
await deps.engine.settle(owner.chat, owner.turn);
|
|
2066
|
+
const run = characterRunner({
|
|
2067
|
+
parent: agent,
|
|
2068
|
+
boundaries: deps.boundaries,
|
|
2069
|
+
store: storeOf(owner.chat)
|
|
2070
|
+
});
|
|
2071
|
+
return record(await deps.engine.activate(owner, {
|
|
2072
|
+
situation: args.situation,
|
|
2073
|
+
characters: args.characters
|
|
2074
|
+
}, run, exec.signal));
|
|
2075
|
+
}
|
|
2076
|
+
});
|
|
2077
|
+
const resolve = defineTool({
|
|
2078
|
+
name: RESOLVE_TOOL,
|
|
2079
|
+
description: "Decide what actually happens to each character that acted in the current round, from their intents and the scene only. Intents can conflict; settle them consistently. A character whose intent fails and who was highly committed gets one more chance, and you resolve that attempt too. The player's character is not asked to act, but you may include an outcome for it (its key is in the scene) when what the player did moves it somewhere or has it handle things; when nobody else needs to react (the player just walks somewhere, picks something up), call this with only that outcome, without activate_characters. When nobody retries, the round is recorded and you decide whether another round is needed or the turn goes back to the player.",
|
|
2080
|
+
parameters: {
|
|
2081
|
+
outcomes: {
|
|
2082
|
+
type: "array",
|
|
2083
|
+
required: true,
|
|
2084
|
+
items: {
|
|
2085
|
+
type: "object",
|
|
2086
|
+
additionalProperties: false,
|
|
2087
|
+
properties: {
|
|
2088
|
+
character: {
|
|
2089
|
+
type: "string",
|
|
2090
|
+
required: true,
|
|
2091
|
+
description: "The character's key; for the player's character, only when it moves or handles things; in an out-of-character command, any character of the story."
|
|
2092
|
+
},
|
|
2093
|
+
result: {
|
|
2094
|
+
type: "string",
|
|
2095
|
+
required: true,
|
|
2096
|
+
enum: RESULTS,
|
|
2097
|
+
description: "Whether the character's intent went through."
|
|
2098
|
+
},
|
|
2099
|
+
summary: {
|
|
2100
|
+
type: "string",
|
|
2101
|
+
required: true,
|
|
2102
|
+
description: "What concretely happens to the character, in a sentence. It becomes what the character is doing."
|
|
2103
|
+
},
|
|
2104
|
+
roll: {
|
|
2105
|
+
type: "integer",
|
|
2106
|
+
description: "The id of the dice roll that decided this outcome (the id roll_check gave), when you rolled for it: the result you give must be the roll's."
|
|
2107
|
+
},
|
|
2108
|
+
spoken: {
|
|
2109
|
+
type: "boolean",
|
|
2110
|
+
description: "Whether the character gets to say its utterance. It does unless something prevents it, such as being silenced or knocked out first."
|
|
2111
|
+
},
|
|
2112
|
+
public_state: {
|
|
2113
|
+
type: "string",
|
|
2114
|
+
description: "What anyone present can now see or infer about the character, when that changed."
|
|
2115
|
+
},
|
|
2116
|
+
item_changes: {
|
|
2117
|
+
type: "array",
|
|
2118
|
+
description: "What the character does with things as a result, in order, when it does: leave out when it handles nothing. Each is checked, and you are told why when it cannot be done. Not for a character whose intent failed.",
|
|
2119
|
+
items: {
|
|
2120
|
+
type: "object",
|
|
2121
|
+
additionalProperties: false,
|
|
2122
|
+
properties: {
|
|
2123
|
+
item: {
|
|
2124
|
+
type: "string",
|
|
2125
|
+
required: true,
|
|
2126
|
+
description: "The key of the item, as the scene lists it. Leave a way's lock to exit."
|
|
2127
|
+
},
|
|
2128
|
+
action: {
|
|
2129
|
+
type: "string",
|
|
2130
|
+
required: true,
|
|
2131
|
+
enum: ITEM_ACTIONS,
|
|
2132
|
+
description: "take (pick up what is here or take it out of a container it carries), drop (leave it here), give (to someone present), put (into an open container), wear, remove (what is worn), open, close, lock, unlock, reveal (find what was hidden)."
|
|
2133
|
+
},
|
|
2134
|
+
to: {
|
|
2135
|
+
type: "string",
|
|
2136
|
+
description: "For give: who gets it. For put: the container."
|
|
2137
|
+
},
|
|
2138
|
+
quantity: {
|
|
2139
|
+
type: "integer",
|
|
2140
|
+
description: "How many, of a pile; all when left out."
|
|
2141
|
+
},
|
|
2142
|
+
position: {
|
|
2143
|
+
type: "string",
|
|
2144
|
+
description: "Where, in words, for drop and put."
|
|
2145
|
+
},
|
|
2146
|
+
feature: {
|
|
2147
|
+
type: "string",
|
|
2148
|
+
description: "For drop: the feature of the place it is left at."
|
|
2149
|
+
},
|
|
2150
|
+
with: {
|
|
2151
|
+
type: "string",
|
|
2152
|
+
description: "For lock and unlock: the key item used. It has to be in hand and fit the lock."
|
|
2153
|
+
},
|
|
2154
|
+
exit: {
|
|
2155
|
+
type: "string",
|
|
2156
|
+
description: "For lock and unlock of a way instead of an item: the key of the place it leads to."
|
|
2157
|
+
},
|
|
2158
|
+
forced: {
|
|
2159
|
+
type: "boolean",
|
|
2160
|
+
description: "Only when the story breaks the lock (picked, smashed): no key is needed."
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
},
|
|
2165
|
+
variable_changes: {
|
|
2166
|
+
type: "array",
|
|
2167
|
+
description: "What this changes of what the story keeps track of (the scene lists it; list_variables shows what exists): a feeling, an injury, a flag, a debt. Only what the outcome establishes; to is the new value (a number, true or false, or one of the words of a choice), by is an amount a number goes up or down (it stops at its bounds).",
|
|
2168
|
+
items: {
|
|
2169
|
+
type: "object",
|
|
2170
|
+
additionalProperties: false,
|
|
2171
|
+
properties: {
|
|
2172
|
+
variable: {
|
|
2173
|
+
type: "string",
|
|
2174
|
+
required: true,
|
|
2175
|
+
description: "The key of the variable."
|
|
2176
|
+
},
|
|
2177
|
+
subject: {
|
|
2178
|
+
type: "string",
|
|
2179
|
+
required: true,
|
|
2180
|
+
description: "The key of the character, item or place it is about; world for the whole story."
|
|
2181
|
+
},
|
|
2182
|
+
to: {
|
|
2183
|
+
oneOf: [
|
|
2184
|
+
{ type: "number" },
|
|
2185
|
+
{ type: "boolean" },
|
|
2186
|
+
{ type: "string" }
|
|
2187
|
+
],
|
|
2188
|
+
description: "The new value."
|
|
2189
|
+
},
|
|
2190
|
+
by: {
|
|
2191
|
+
type: "number",
|
|
2192
|
+
description: "How much a number goes up (positive) or down (negative)."
|
|
2193
|
+
},
|
|
2194
|
+
baseline: {
|
|
2195
|
+
oneOf: [
|
|
2196
|
+
{ type: "number" },
|
|
2197
|
+
{ type: "boolean" },
|
|
2198
|
+
{ type: "string" }
|
|
2199
|
+
],
|
|
2200
|
+
description: "For a variable with a temperament (feelings): the new baseline, when what happened changes it lastingly."
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
},
|
|
2205
|
+
moves_to: {
|
|
2206
|
+
type: "object",
|
|
2207
|
+
additionalProperties: false,
|
|
2208
|
+
description: "Where the character ends up if it goes somewhere as a result: leave out when it stays. It must be possible (a way over open exits); you are told why if it is not. Not for a character whose intent failed. A journey takes at least as long as the ways on it say, whatever elapsed_seconds you give.",
|
|
2209
|
+
properties: {
|
|
2210
|
+
location: {
|
|
2211
|
+
type: "string",
|
|
2212
|
+
required: true,
|
|
2213
|
+
description: "The key of the place, as the scene lists it."
|
|
2214
|
+
},
|
|
2215
|
+
position: {
|
|
2216
|
+
type: "string",
|
|
2217
|
+
description: "Where in the place, in words: \"by the window\"."
|
|
2218
|
+
},
|
|
2219
|
+
feature: {
|
|
2220
|
+
type: "string",
|
|
2221
|
+
description: "The key of a feature of that place it is at."
|
|
2222
|
+
},
|
|
2223
|
+
ignore_exits: {
|
|
2224
|
+
type: "boolean",
|
|
2225
|
+
description: "Only when the story itself carries it (carried off, teleported, falls): the exits do not matter."
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
},
|
|
2232
|
+
elapsed_seconds: {
|
|
2233
|
+
type: "integer",
|
|
2234
|
+
description: "How long this round took in the story, in seconds:: a few seconds for a remark, a minute or two for a conversation, longer for work or a journey. Left out, the chat's default applies. Not when the story's time follows the wall clock."
|
|
2235
|
+
}
|
|
2236
|
+
},
|
|
2237
|
+
output: {
|
|
2238
|
+
schema: { type: "json" },
|
|
2239
|
+
render: (_args, value) => [{
|
|
2240
|
+
type: "text",
|
|
2241
|
+
text: renderResolution(value)
|
|
2242
|
+
}]
|
|
2243
|
+
},
|
|
2244
|
+
isConcurrencySafe: () => false,
|
|
2245
|
+
async execute(args, exec) {
|
|
2246
|
+
const { agent, owner } = ownerOf(exec.agent);
|
|
2247
|
+
await deps.engine.settle(owner.chat, owner.turn);
|
|
2248
|
+
const run = characterRunner({
|
|
2249
|
+
parent: agent,
|
|
2250
|
+
boundaries: deps.boundaries,
|
|
2251
|
+
store: storeOf(owner.chat)
|
|
2252
|
+
});
|
|
2253
|
+
const outcomes = args.outcomes.map((outcome) => ({
|
|
2254
|
+
character: outcome.character,
|
|
2255
|
+
result: outcome.result,
|
|
2256
|
+
summary: outcome.summary,
|
|
2257
|
+
...outcome.public_state === void 0 ? {} : { publicState: outcome.public_state },
|
|
2258
|
+
...outcome.spoken === void 0 ? {} : { spoken: outcome.spoken },
|
|
2259
|
+
...outcome.roll === void 0 ? {} : { roll: outcome.roll },
|
|
2260
|
+
...outcome.item_changes === void 0 || outcome.item_changes.length === 0 ? {} : { itemChanges: outcome.item_changes.map((change) => ({
|
|
2261
|
+
item: change.item,
|
|
2262
|
+
action: change.action,
|
|
2263
|
+
...change.to === void 0 ? {} : { to: change.to },
|
|
2264
|
+
...change.quantity === void 0 ? {} : { quantity: change.quantity },
|
|
2265
|
+
...change.position === void 0 ? {} : { position: change.position },
|
|
2266
|
+
...change.feature === void 0 ? {} : { feature: change.feature },
|
|
2267
|
+
...change.with === void 0 ? {} : { with: change.with },
|
|
2268
|
+
...change.exit === void 0 ? {} : { exit: change.exit },
|
|
2269
|
+
...change.forced === true ? { forced: true } : {}
|
|
2270
|
+
})) },
|
|
2271
|
+
...outcome.variable_changes === void 0 || outcome.variable_changes.length === 0 ? {} : { variableChanges: outcome.variable_changes.map((change) => ({
|
|
2272
|
+
variable: change.variable,
|
|
2273
|
+
subject: change.subject,
|
|
2274
|
+
...change.to === void 0 ? {} : { to: change.to },
|
|
2275
|
+
...change.by === void 0 ? {} : { by: change.by },
|
|
2276
|
+
...change.baseline === void 0 ? {} : { baseline: change.baseline }
|
|
2277
|
+
})) },
|
|
2278
|
+
...outcome.moves_to === void 0 ? {} : { moveTo: {
|
|
2279
|
+
location: outcome.moves_to.location,
|
|
2280
|
+
...outcome.moves_to.position === void 0 ? {} : { position: outcome.moves_to.position },
|
|
2281
|
+
...outcome.moves_to.feature === void 0 ? {} : { feature: outcome.moves_to.feature },
|
|
2282
|
+
...outcome.moves_to.ignore_exits === true ? { ignoreExits: true } : {}
|
|
2283
|
+
} }
|
|
2284
|
+
}));
|
|
2285
|
+
return record(await deps.engine.resolve(owner, outcomes, run, exec.signal, args.elapsed_seconds));
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
const narrate = defineTool({
|
|
2289
|
+
name: NARRATE_TOOL,
|
|
2290
|
+
description: "Deliver the output of the turn to the player and give control back to them, once at least one round is recorded: the characters' utterances from all the rounds and your narration, as ordered segments. Every utterance a character gave must appear exactly once, exactly as given and in the order spoken; narration is free. An output that changes, drops, invents or reorders an utterance is refused with what is wrong.",
|
|
2291
|
+
parameters: {
|
|
2292
|
+
segments: {
|
|
2293
|
+
type: "array",
|
|
2294
|
+
description: "The output in order. Leave out only when a narrator other than you writes the output.",
|
|
2295
|
+
items: {
|
|
2296
|
+
type: "object",
|
|
2297
|
+
additionalProperties: false,
|
|
2298
|
+
properties: {
|
|
2299
|
+
type: {
|
|
2300
|
+
type: "string",
|
|
2301
|
+
required: true,
|
|
2302
|
+
enum: ["utterance", "narration"]
|
|
2303
|
+
},
|
|
2304
|
+
character: {
|
|
2305
|
+
type: "string",
|
|
2306
|
+
description: "For an utterance: the key of the character who says it."
|
|
2307
|
+
},
|
|
2308
|
+
text: {
|
|
2309
|
+
type: "string",
|
|
2310
|
+
required: true,
|
|
2311
|
+
description: "For an utterance: the words exactly as the character gave them, without quotation marks. For narration: what the player reads."
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
},
|
|
2316
|
+
addressed: {
|
|
2317
|
+
type: "array",
|
|
2318
|
+
items: { type: "integer" },
|
|
2319
|
+
description: "The ids of the beats you were told to weave in that this output does. Beats you do not address are told again, then let go."
|
|
2320
|
+
}
|
|
2321
|
+
},
|
|
2322
|
+
output: {
|
|
2323
|
+
schema: { type: "json" },
|
|
2324
|
+
render: (_args, value) => {
|
|
2325
|
+
const output = value;
|
|
2326
|
+
return [{
|
|
2327
|
+
type: "text",
|
|
2328
|
+
text: `${output.repaired ? "The output was corrected so that every utterance appears exactly as the characters gave it, and has been delivered to the player. The turn ends here." : "The output has been delivered to the player. The turn ends here."}\n${encodeOutput(output)}`
|
|
2329
|
+
}];
|
|
2330
|
+
}
|
|
2331
|
+
},
|
|
2332
|
+
isConcurrencySafe: () => false,
|
|
2333
|
+
async execute(args, exec) {
|
|
2334
|
+
const { agent, owner } = ownerOf(exec.agent);
|
|
2335
|
+
await deps.engine.settle(owner.chat, owner.turn);
|
|
2336
|
+
const segments = (args.segments ?? []).map((segment) => ({
|
|
2337
|
+
type: segment.type,
|
|
2338
|
+
text: segment.text,
|
|
2339
|
+
...segment.character === void 0 ? {} : { character: segment.character }
|
|
2340
|
+
}));
|
|
2341
|
+
const output = await deps.engine.narrate(owner, segments, characterRunner({
|
|
2342
|
+
parent: agent,
|
|
2343
|
+
boundaries: deps.boundaries,
|
|
2344
|
+
store: storeOf(owner.chat)
|
|
2345
|
+
}), args.addressed ?? []);
|
|
2346
|
+
const timelineNode = deps.delivered?.(owner.chat, output);
|
|
2347
|
+
const delivered = timelineNode === void 0 ? output : {
|
|
2348
|
+
...output,
|
|
2349
|
+
timelineNode
|
|
2350
|
+
};
|
|
2351
|
+
exec.concludeTurn();
|
|
2352
|
+
return record(delivered);
|
|
2353
|
+
}
|
|
2354
|
+
});
|
|
2355
|
+
const remember = defineTool({
|
|
2356
|
+
name: RECORD_TOOL,
|
|
2357
|
+
description: "Have the memory keeper write what happened since the last record into the story's lasting memory: the events, what each character took in of them, what they now believe, and the threads left open. It works in the background and covers every round still waiting, from this turn and earlier ones. Call it when the story changes phase, not after every round; rounds you do not record are kept and recorded together later.",
|
|
2358
|
+
parameters: { focus: {
|
|
2359
|
+
type: "string",
|
|
2360
|
+
description: "What is worth keeping, in a sentence: the decision, revelation or change that matters. The keeper writes it first and may leave out incidental detail."
|
|
2361
|
+
} },
|
|
2362
|
+
output: {
|
|
2363
|
+
schema: { type: "json" },
|
|
2364
|
+
render: (_args, value) => [{
|
|
2365
|
+
type: "text",
|
|
2366
|
+
text: `The memory keeper is writing ${value.rounds} round${value.rounds === 1 ? "" : "s"} into the story's memory.`
|
|
2367
|
+
}]
|
|
2368
|
+
},
|
|
2369
|
+
isConcurrencySafe: () => false,
|
|
2370
|
+
execute(args, exec) {
|
|
2371
|
+
const { owner } = ownerOf(exec.agent);
|
|
2372
|
+
return Promise.resolve(record({ rounds: deps.engine.record(owner, args.focus) }));
|
|
2373
|
+
}
|
|
2374
|
+
});
|
|
2375
|
+
const plot = defineTool({
|
|
2376
|
+
name: PLOT_TOOL,
|
|
2377
|
+
description: "Record only what play has already established about an optional plot. introduced means the named opportunity actually became perceptible in the resolved round, not merely that the pacing note suggested it. rejected means the player clearly declined that specific hook. resolved or abandoned applies to the plot as a whole. This records pacing state; it creates no event and makes nothing happen.",
|
|
2378
|
+
parameters: {
|
|
2379
|
+
plot: {
|
|
2380
|
+
type: "string",
|
|
2381
|
+
required: true,
|
|
2382
|
+
description: "The plot id from the pacing opportunity."
|
|
2383
|
+
},
|
|
2384
|
+
development: {
|
|
2385
|
+
type: "string",
|
|
2386
|
+
description: "The development id; required for introduced or rejected."
|
|
2387
|
+
},
|
|
2388
|
+
action: {
|
|
2389
|
+
type: "string",
|
|
2390
|
+
required: true,
|
|
2391
|
+
enum: [
|
|
2392
|
+
"introduced",
|
|
2393
|
+
"rejected",
|
|
2394
|
+
"resolved",
|
|
2395
|
+
"abandoned"
|
|
2396
|
+
]
|
|
2397
|
+
}
|
|
2398
|
+
},
|
|
2399
|
+
output: {
|
|
2400
|
+
schema: { type: "json" },
|
|
2401
|
+
render: (_args, value) => [{
|
|
2402
|
+
type: "text",
|
|
2403
|
+
text: `Plot pacing recorded: ${value.plot.name} is ${value.status}.`
|
|
2404
|
+
}]
|
|
2405
|
+
},
|
|
2406
|
+
isConcurrencySafe: () => false,
|
|
2407
|
+
execute(args, exec) {
|
|
2408
|
+
const { owner } = ownerOf(exec.agent);
|
|
2409
|
+
return Promise.resolve(record(updatePlotProgress(storeOf(owner.chat), args.plot, args.development, args.action)));
|
|
2410
|
+
}
|
|
2411
|
+
});
|
|
2412
|
+
const makePlot = defineTool({
|
|
2413
|
+
name: AUTHOR_PLOT_TOOL,
|
|
2414
|
+
description: "Ask a plot author for one optional, branching dramatic scaffold grounded in the current session. Use only when the scene explicitly says the quiet story has no plot scaffold and a reusable tension would help. It creates possibilities, not events, actions or obligations; do not introduce any part until a later pacing opportunity fits.",
|
|
2415
|
+
parameters: {},
|
|
2416
|
+
output: {
|
|
2417
|
+
schema: { type: "json" },
|
|
2418
|
+
render: (_args, value) => {
|
|
2419
|
+
const made = value;
|
|
2420
|
+
return [{
|
|
2421
|
+
type: "text",
|
|
2422
|
+
text: `Authored optional plot ${made.name} [${made.id}]: ${made.premise}. Nothing in it has happened. Continue this turn normally; a later pacing opportunity may offer a hook.`
|
|
2423
|
+
}];
|
|
2424
|
+
}
|
|
2425
|
+
},
|
|
2426
|
+
isConcurrencySafe: () => false,
|
|
2427
|
+
async execute(_args, exec) {
|
|
2428
|
+
const { agent, owner } = ownerOf(exec.agent);
|
|
2429
|
+
const store = storeOf(owner.chat);
|
|
2430
|
+
if (!plotAuthorNeeded(store, owner.turn)) throw new Error("the story does not currently need a plot author; continue with its existing plots, threads and character goals");
|
|
2431
|
+
return record(await authorPlot(agent, store, owner.turn, exec.signal));
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
const expand = defineTool({
|
|
2435
|
+
name: EXPAND_TOOL,
|
|
2436
|
+
description: "Have a new character or place made up and fitted into the world, only when the story genuinely needs it. Valid reasons: scene_change (the story has actually gone somewhere that no known place covers, even as part of one), arrival (someone new has actually arrived or been brought into the scene), introduction (a specific person who has not appeared is needed by what is happening now and the story has established who they are), object (a thing so important or so complex that it needs inventing, such as an artifact with properties or a vehicle; or a place on the body that the world has no slot for; ordinary things the story uses are yours to bring in with introduce_thing), trigger (the story set up a moment that is bound to come, such as a deadline given, a promised arrival or a trap laid, that can be stated as a condition: a time, someone in a place, a thing held, a variable, an event), variable (a quantity, state or choice the story established matters from here on and nothing tracked fits: a debt, a health, a reputation). Not valid: colour, atmosphere, filling a quiet scene, something mentioned in passing, a passer-by or a crowd, scenery, or anything an existing character, place or thing can serve; use those. Ordinary things go through introduce_thing. A world author decides, and may decline and say what exists that can serve. A few things at most per turn.",
|
|
2437
|
+
parameters: {
|
|
2438
|
+
need: {
|
|
2439
|
+
type: "string",
|
|
2440
|
+
required: true,
|
|
2441
|
+
enum: AUTHORING_NEEDS,
|
|
2442
|
+
description: "Why: scene_change, arrival, introduction, object, variable or trigger."
|
|
2443
|
+
},
|
|
2444
|
+
what: {
|
|
2445
|
+
type: "string",
|
|
2446
|
+
required: true,
|
|
2447
|
+
description: "What is needed, from what the story has established: who or where (a name when it was given), their role, what happened to make it needed now, and where it is in relation to what exists."
|
|
2448
|
+
}
|
|
2449
|
+
},
|
|
2450
|
+
output: {
|
|
2451
|
+
schema: { type: "json" },
|
|
2452
|
+
render: (_args, value) => [{
|
|
2453
|
+
type: "text",
|
|
2454
|
+
text: renderExpansion(value)
|
|
2455
|
+
}]
|
|
2456
|
+
},
|
|
2457
|
+
isConcurrencySafe: () => false,
|
|
2458
|
+
async execute(args, exec) {
|
|
2459
|
+
const { owner } = ownerOf(exec.agent);
|
|
2460
|
+
await deps.engine.settle(owner.chat, owner.turn);
|
|
2461
|
+
return record(await deps.engine.expand(owner, {
|
|
2462
|
+
need: args.need,
|
|
2463
|
+
what: args.what
|
|
2464
|
+
}, exec.signal));
|
|
2465
|
+
}
|
|
2466
|
+
});
|
|
2467
|
+
const introduce = defineTool({
|
|
2468
|
+
name: INTRODUCE_TOOL,
|
|
2469
|
+
description: "Bring a thing into the story as a table's game master would: something the story is about to use or that the player can find, take or handle (a barricade, a tool, a note, a bottle, a key) and that does not exist yet. It is made at once, where you say: at a place (at, a place key; the player's place when you say nothing), in someone's hands (held_by, a character key) or inside a thing (inside, an item key). Afterwards it is a thing like any other: use its key in item_changes. Not for scenery nobody will touch (that is just part of the place), not for something important and complex enough to need a world author (use expand_world, reason object), and never for what exists already (list_items). A few things at most per turn.",
|
|
2470
|
+
parameters: {
|
|
2471
|
+
name: {
|
|
2472
|
+
type: "string",
|
|
2473
|
+
required: true,
|
|
2474
|
+
description: "What it is called, as the story names it."
|
|
2475
|
+
},
|
|
2476
|
+
description: {
|
|
2477
|
+
type: "string",
|
|
2478
|
+
description: "One or two sentences: what it looks like, what it is made of, what state it is in."
|
|
2479
|
+
},
|
|
2480
|
+
quantity: {
|
|
2481
|
+
type: "integer",
|
|
2482
|
+
description: "How many, when it is a number of the same thing (default 1)."
|
|
2483
|
+
},
|
|
2484
|
+
quality: {
|
|
2485
|
+
type: "string",
|
|
2486
|
+
description: "Its condition in a word or two (rusty, new), when that matters."
|
|
2487
|
+
},
|
|
2488
|
+
notable: {
|
|
2489
|
+
type: "boolean",
|
|
2490
|
+
description: "Whether the characters present would notice it at once."
|
|
2491
|
+
},
|
|
2492
|
+
hidden: {
|
|
2493
|
+
type: "boolean",
|
|
2494
|
+
description: "Whether it starts out of sight (until a round reveals it)."
|
|
2495
|
+
},
|
|
2496
|
+
at: {
|
|
2497
|
+
type: "string",
|
|
2498
|
+
description: "The key of the place it lies in."
|
|
2499
|
+
},
|
|
2500
|
+
held_by: {
|
|
2501
|
+
type: "string",
|
|
2502
|
+
description: "The key of the character who holds it."
|
|
2503
|
+
},
|
|
2504
|
+
inside: {
|
|
2505
|
+
type: "string",
|
|
2506
|
+
description: "The key of the container it is in."
|
|
2507
|
+
}
|
|
2508
|
+
},
|
|
2509
|
+
output: {
|
|
2510
|
+
schema: { type: "json" },
|
|
2511
|
+
render: (_args, value) => {
|
|
2512
|
+
const made = value;
|
|
2513
|
+
return [{
|
|
2514
|
+
type: "text",
|
|
2515
|
+
text: `Introduced ${made.name} [${made.key}], ${made.where}. Use the key in item_changes; nobody has taken it up yet.`
|
|
2516
|
+
}];
|
|
2517
|
+
}
|
|
2518
|
+
},
|
|
2519
|
+
isConcurrencySafe: () => false,
|
|
2520
|
+
async execute(args, exec) {
|
|
2521
|
+
const { owner } = ownerOf(exec.agent);
|
|
2522
|
+
await deps.engine.settle(owner.chat, owner.turn);
|
|
2523
|
+
return record(deps.engine.introduce(owner, {
|
|
2524
|
+
name: args.name,
|
|
2525
|
+
...args.description === void 0 ? {} : { description: args.description },
|
|
2526
|
+
...args.quantity === void 0 ? {} : { quantity: args.quantity },
|
|
2527
|
+
...args.quality === void 0 ? {} : { quality: args.quality },
|
|
2528
|
+
...args.notable === void 0 ? {} : { notable: args.notable },
|
|
2529
|
+
...args.hidden === void 0 ? {} : { hidden: args.hidden },
|
|
2530
|
+
...args.at === void 0 ? {} : { at: args.at },
|
|
2531
|
+
...args.held_by === void 0 ? {} : { heldBy: args.held_by },
|
|
2532
|
+
...args.inside === void 0 ? {} : { inside: args.inside }
|
|
2533
|
+
}));
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
const skip = defineTool({
|
|
2537
|
+
name: TIME_TOOL,
|
|
2538
|
+
description: "Skip ahead in the story's time, between rounds: the player's character sleeps till morning, waits, or travels for days. Say either how long (by_minutes) or until when (until_time, and days_later for a later day). Time does not otherwise pass faster than the rounds take; use this only for a stretch that is summarised rather than played. Nothing else changes: if the skip changes what characters are doing or where they are, run a round for them afterwards. Not available when the story's time follows the wall clock.",
|
|
2539
|
+
parameters: {
|
|
2540
|
+
reason: {
|
|
2541
|
+
type: "string",
|
|
2542
|
+
required: true,
|
|
2543
|
+
description: "What happens in the time that passes, in a sentence (\"they sleep\", \"the ferry crosses\")."
|
|
2544
|
+
},
|
|
2545
|
+
by_minutes: {
|
|
2546
|
+
type: "integer",
|
|
2547
|
+
description: "How many minutes to skip."
|
|
2548
|
+
},
|
|
2549
|
+
until_time: {
|
|
2550
|
+
type: "string",
|
|
2551
|
+
description: "The time of day to skip to, 24-hour HH:MM: the next time the clock reads it, or the day given by days_later."
|
|
2552
|
+
},
|
|
2553
|
+
days_later: {
|
|
2554
|
+
type: "integer",
|
|
2555
|
+
description: "With until_time: that many days after today (0 is later today, 1 is tomorrow)."
|
|
2556
|
+
}
|
|
2557
|
+
},
|
|
2558
|
+
output: {
|
|
2559
|
+
schema: { type: "json" },
|
|
2560
|
+
render: (_args, value) => {
|
|
2561
|
+
const done = value;
|
|
2562
|
+
return [{
|
|
2563
|
+
type: "text",
|
|
2564
|
+
text: `${describeDuration(done.to - done.from)} pass. It is now ${describeTime({
|
|
2565
|
+
now: done.to,
|
|
2566
|
+
zone: done.zone
|
|
2567
|
+
})}.${done.moved.length === 0 ? "" : ` ${done.moved.map(routineLine).join(" ")}`} Nothing else changed: characters with you are still doing what they were, where they were; run a round for them if the time that passed changes that.${done.world.length === 0 ? "" : `\n${renderWorld(done.world).join("\n")}`}`
|
|
2568
|
+
}];
|
|
2569
|
+
}
|
|
2570
|
+
},
|
|
2571
|
+
isConcurrencySafe: () => false,
|
|
2572
|
+
async execute(args, exec) {
|
|
2573
|
+
const { owner } = ownerOf(exec.agent);
|
|
2574
|
+
await deps.engine.settle(owner.chat, owner.turn);
|
|
2575
|
+
if ([args.by_minutes !== void 0, args.until_time !== void 0].filter(Boolean).length !== 1) throw new Error("give exactly one of by_minutes and until_time");
|
|
2576
|
+
if (args.days_later !== void 0 && args.until_time === void 0) throw new Error("days_later goes with until_time");
|
|
2577
|
+
const request = args.by_minutes !== void 0 ? {
|
|
2578
|
+
byMinutes: args.by_minutes,
|
|
2579
|
+
reason: args.reason
|
|
2580
|
+
} : {
|
|
2581
|
+
untilTime: args.until_time ?? "",
|
|
2582
|
+
...args.days_later === void 0 ? {} : { daysLater: args.days_later },
|
|
2583
|
+
reason: args.reason
|
|
2584
|
+
};
|
|
2585
|
+
return record(deps.engine.advanceTime(owner, request));
|
|
2586
|
+
}
|
|
2587
|
+
});
|
|
2588
|
+
const preview = defineTool({
|
|
2589
|
+
name: PREVIEW_TOOL,
|
|
2590
|
+
description: "Show the player how the scene opens, as your very first action of a turn, before you ask any character: two or three sentences that set the mood and what the player's character perceives, ending on the open question of the moment. It is on screen at once, while the characters are still being asked, and is replaced in the player's view by the output you deliver with narrate, which may use it, change it or start over. Describe only what the scene and the player's own action establish: never what any other character does, says, decides or thinks, and nothing the player's character cannot perceive. Once per message.",
|
|
2591
|
+
parameters: { text: {
|
|
2592
|
+
type: "string",
|
|
2593
|
+
required: true,
|
|
2594
|
+
description: "The opening, plain prose in the narration voice."
|
|
2595
|
+
} },
|
|
2596
|
+
output: {
|
|
2597
|
+
schema: { type: "json" },
|
|
2598
|
+
render: (_args, value) => [{
|
|
2599
|
+
type: "text",
|
|
2600
|
+
text: `${encodePreview(value.text)}\nShown to the player. Now call activate_characters.`
|
|
2601
|
+
}]
|
|
2602
|
+
},
|
|
2603
|
+
isConcurrencySafe: () => false,
|
|
2604
|
+
execute(args, exec) {
|
|
2605
|
+
const { owner } = ownerOf(exec.agent);
|
|
2606
|
+
return Promise.resolve(record({ text: deps.engine.preview(owner, args.text) }));
|
|
2607
|
+
}
|
|
2608
|
+
});
|
|
2609
|
+
const ruling = defineTool({
|
|
2610
|
+
name: RULING_TOOL,
|
|
2611
|
+
description: "Rule on the player's out-of-character command, as the very first thing of an out-of-character turn: legal is false only when the command breaks the rules of the world or the player's own rules (the scene lists them); what is merely strange, impossible for the characters, or hard on them is legal, because the player may change the story itself. The reason is shown to the player, so write it plainly to them. Only a legal ruling lets you change anything.",
|
|
2612
|
+
parameters: {
|
|
2613
|
+
rule_check: {
|
|
2614
|
+
type: "string",
|
|
2615
|
+
required: true,
|
|
2616
|
+
description: "First, go through every rule the scene lists, one by one, in a few words each: does the command need what the rule excludes (the rules are literal: a rule against magic is broken by anything magical, however the command words it, and strange is not the same as against a rule)? Write \"no rules listed\" when there are none."
|
|
2617
|
+
},
|
|
2618
|
+
legal: {
|
|
2619
|
+
type: "boolean",
|
|
2620
|
+
required: true,
|
|
2621
|
+
description: "Whether the command is allowed: false when any listed rule is broken."
|
|
2622
|
+
},
|
|
2623
|
+
reason: {
|
|
2624
|
+
type: "string",
|
|
2625
|
+
required: true,
|
|
2626
|
+
description: "To the player, in plain words and briefly: what you will do, or which rule it breaks."
|
|
2627
|
+
}
|
|
2628
|
+
},
|
|
2629
|
+
output: {
|
|
2630
|
+
schema: { type: "json" },
|
|
2631
|
+
render: (_args, value) => [{
|
|
2632
|
+
type: "text",
|
|
2633
|
+
text: value.legal ? `Ruled legal. Now make it happen: ${RESOLVE_TOOL} (outcomes for any characters, asked or not, with their moves and things), ${EXPAND_TOOL} (for what does not exist yet), ${TIME_TOOL}; do only what the command says. Then call ${NARRATE_TOOL} with narration only, of what the player can perceive.` : `Ruled illegal; nothing changes. Call ${NARRATE_TOOL} with no segments: the player is told why.`
|
|
2634
|
+
}]
|
|
2635
|
+
},
|
|
2636
|
+
isConcurrencySafe: () => false,
|
|
2637
|
+
execute(args, exec) {
|
|
2638
|
+
const { owner } = ownerOf(exec.agent);
|
|
2639
|
+
return Promise.resolve(record(deps.engine.rule(owner, args.legal, args.reason)));
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
const answer = defineTool({
|
|
2643
|
+
name: ANSWER_TOOL,
|
|
2644
|
+
description: "Have the player's out-of-character question answered, as the very first thing of a question turn. You do not write the answer: it is written from what the player's character knows (what it remembers, knows to exist, carries and sees where it is), so that nothing hidden is given away. Nothing in the story changes, nobody is asked to act and time does not pass.",
|
|
2645
|
+
parameters: {},
|
|
2646
|
+
output: {
|
|
2647
|
+
schema: { type: "json" },
|
|
2648
|
+
render: () => [{
|
|
2649
|
+
type: "text",
|
|
2650
|
+
text: `The player is shown the answer. Now call ${NARRATE_TOOL} with no segments.`
|
|
2651
|
+
}]
|
|
2652
|
+
},
|
|
2653
|
+
isConcurrencySafe: () => false,
|
|
2654
|
+
async execute(_args, exec) {
|
|
2655
|
+
const { agent, owner } = ownerOf(exec.agent);
|
|
2656
|
+
return record(await deps.engine.answer(owner, answerRunner({
|
|
2657
|
+
parent: agent,
|
|
2658
|
+
boundaries: deps.boundaries,
|
|
2659
|
+
store: storeOf(owner.chat)
|
|
2660
|
+
}), exec.signal));
|
|
2661
|
+
}
|
|
2662
|
+
});
|
|
2663
|
+
return [
|
|
2664
|
+
defineTool({
|
|
2665
|
+
name: JUDGE_TOOL,
|
|
2666
|
+
description: "Judge what the player's character tries, as the very first thing of an ordinary turn (nothing else is accepted before it): allowed is false when it is not viable (what it needs is out of reach, is not there, or the character cannot do it or does not have it) or when it breaks a rule of the world or of the player (the scene lists them and they are absolute: no magic means no spell works). The player's claim of an effect is not a fact. What merely looks strange, rash or foolish is allowed. When it is not allowed the attempt is played as a failure for the player's character, and nobody is asked to act on it.",
|
|
2667
|
+
parameters: {
|
|
2668
|
+
rule_check: {
|
|
2669
|
+
type: "string",
|
|
2670
|
+
required: true,
|
|
2671
|
+
description: "First, go through every rule the scene lists, one by one, in a few words each: does what the character tries need what the rule excludes? The rules are literal. Then whether it is viable here. Write \"no rules listed\" when there are none."
|
|
2672
|
+
},
|
|
2673
|
+
at: {
|
|
2674
|
+
type: "string",
|
|
2675
|
+
description: "The key of the place where the action happens, only when the player says it happens at a particular place (talking to the baker in the market, searching the cellar) rather than where the character is. If the character is somewhere else the action cannot work: it has to go there first. Leave it out when the action happens where the character is, and when the player is going somewhere (the journey is its own action)."
|
|
2676
|
+
},
|
|
2677
|
+
allowed: {
|
|
2678
|
+
type: "boolean",
|
|
2679
|
+
required: true,
|
|
2680
|
+
description: "Whether what the character tries can work: false when any listed rule is broken or it is not viable."
|
|
2681
|
+
},
|
|
2682
|
+
uncertain: {
|
|
2683
|
+
type: "boolean",
|
|
2684
|
+
required: true,
|
|
2685
|
+
description: "Always answer, when it can work: true when it can plainly go either way and the result matters to the story, such as talking round someone wary or hostile, a hard lock, a stealthy approach past someone watching, a climb, a leap, a chase, a fight, a hurried search; false for what plainly succeeds (walking, opening an unlocked door, asking a friendly question) or has nothing at stake. When it is true and you have dice tools, you roll for it before anyone is asked to act and the dice decide; without dice tools it changes nothing."
|
|
2686
|
+
},
|
|
2687
|
+
reason: {
|
|
2688
|
+
type: "string",
|
|
2689
|
+
required: true,
|
|
2690
|
+
description: "What the character tries, and the rule or the fact that decides it, in a sentence."
|
|
2691
|
+
}
|
|
2692
|
+
},
|
|
2693
|
+
output: {
|
|
2694
|
+
schema: { type: "json" },
|
|
2695
|
+
render: (_args, value) => [{
|
|
2696
|
+
type: "text",
|
|
2697
|
+
text: value.allowed ? `Judged: it can work${value.roll === true ? " but it is uncertain: roll for it now with roll_check (list_checks shows the checks), naming the character it is for; nobody is asked to act before the dice are rolled. Then" : ". Now"} call ${PREVIEW_TOOL} (when the scene asks for it) and ${ACTIVATE_TOOL}, describing only what the character does.` : `Judged: it cannot work${value.elsewhere === true ? ` (${value.reason})` : ""}. Play the failed attempt: ${RESOLVE_TOOL} with one outcome for the player's character (result failed, one sentence: what it does, what comes of it, why not) and nothing else, then ${NARRATE_TOOL}. Narrate what a witness would see of the attempt, never the effect the player claimed.`
|
|
2698
|
+
}]
|
|
2699
|
+
},
|
|
2700
|
+
isConcurrencySafe: () => false,
|
|
2701
|
+
execute(args, exec) {
|
|
2702
|
+
const { owner } = ownerOf(exec.agent);
|
|
2703
|
+
return Promise.resolve(record(deps.engine.judge(owner, args.allowed, args.reason, args.at, args.uncertain)));
|
|
2704
|
+
}
|
|
2705
|
+
}),
|
|
2706
|
+
preview,
|
|
2707
|
+
ruling,
|
|
2708
|
+
answer,
|
|
2709
|
+
activate,
|
|
2710
|
+
resolve,
|
|
2711
|
+
skip,
|
|
2712
|
+
remember,
|
|
2713
|
+
expand,
|
|
2714
|
+
introduce,
|
|
2715
|
+
makePlot,
|
|
2716
|
+
plot,
|
|
2717
|
+
narrate
|
|
2718
|
+
];
|
|
2719
|
+
}
|
|
2720
|
+
//#endregion
|
|
2721
|
+
//#region src/shared/tools.ts
|
|
2722
|
+
/** What this version can offer. A name in a settings file or a world that is not here is kept and ignored. */
|
|
2723
|
+
const OPTIONAL_TOOLS = [
|
|
2724
|
+
{
|
|
2725
|
+
id: "roll_check",
|
|
2726
|
+
agent: "gameMaster",
|
|
2727
|
+
default: true
|
|
2728
|
+
},
|
|
2729
|
+
{
|
|
2730
|
+
id: "roll_dice",
|
|
2731
|
+
agent: "gameMaster",
|
|
2732
|
+
default: true
|
|
2733
|
+
},
|
|
2734
|
+
{
|
|
2735
|
+
id: "list_checks",
|
|
2736
|
+
agent: "gameMaster",
|
|
2737
|
+
default: true
|
|
2738
|
+
}
|
|
2739
|
+
];
|
|
2740
|
+
/** Whether an agent of this kind has a tool, by what the switches say and, failing that, by default. A tool this version does not offer is never on. */
|
|
2741
|
+
function toolEnabled(board, agent, id) {
|
|
2742
|
+
const offered = OPTIONAL_TOOLS.find((tool) => tool.agent === agent && tool.id === id);
|
|
2743
|
+
if (offered === void 0) return false;
|
|
2744
|
+
return board[agent]?.[id] ?? offered.default;
|
|
2745
|
+
}
|
|
2746
|
+
/**
|
|
2747
|
+
* Whether an agent of this kind has a tool that is not one of this plugin's own: only when it was switched on. Such tools are off by default, because
|
|
2748
|
+
* they reach beyond the story (files, a shell, the web), and a name that no plugin registers now has no effect.
|
|
2749
|
+
*/
|
|
2750
|
+
function externalEnabled(board, agent, name) {
|
|
2751
|
+
return board[agent]?.[name] === true;
|
|
2752
|
+
}
|
|
2753
|
+
//#endregion
|
|
2754
|
+
//#region src/host/tools/external.ts
|
|
2755
|
+
/** The reserved transport DSH presents tools through; it is never a tool of its own to switch. */
|
|
2756
|
+
const RESERVED = /* @__PURE__ */ new Set(["run_code"]);
|
|
2757
|
+
let own;
|
|
2758
|
+
/** The names of every tool this plugin and the state plugin register themselves: the story's own, which are not for switching here. */
|
|
2759
|
+
function ownToolNames() {
|
|
2760
|
+
own ??= /* @__PURE__ */ new Set([
|
|
2761
|
+
...createTools(() => void 0, {
|
|
2762
|
+
write: true,
|
|
2763
|
+
authoring: true
|
|
2764
|
+
}).map((tool) => tool.name),
|
|
2765
|
+
...createDiceTools(() => void 0).map((tool) => tool.name),
|
|
2766
|
+
...createTools$1({}).map((tool) => tool.name)
|
|
2767
|
+
]);
|
|
2768
|
+
return own;
|
|
2769
|
+
}
|
|
2770
|
+
/** The tools other plugins registered for everyone (a file or shell tool, an MCP server's tools), which a story can give to an agent. */
|
|
2771
|
+
function externalTools(registry) {
|
|
2772
|
+
const mine = ownToolNames();
|
|
2773
|
+
return registry.schemas().filter((tool) => !mine.has(tool.name) && !RESERVED.has(tool.name)).map((tool) => ({
|
|
2774
|
+
name: tool.name,
|
|
2775
|
+
description: tool.description
|
|
2776
|
+
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
2777
|
+
}
|
|
2778
|
+
/** The external tools that are registered now and that an agent of this kind has been given. */
|
|
2779
|
+
function externalGiven(registry, board, agent) {
|
|
2780
|
+
return externalTools(registry).map((tool) => tool.name).filter((name) => externalEnabled(board, agent, name));
|
|
2781
|
+
}
|
|
2782
|
+
/** The external tools that are registered now and that an agent of this kind has not been given: they are taken away from it. */
|
|
2783
|
+
function externalWithheld(registry, board, agent) {
|
|
2784
|
+
return externalTools(registry).map((tool) => tool.name).filter((name) => !externalEnabled(board, agent, name));
|
|
2785
|
+
}
|
|
2786
|
+
//#endregion
|
|
1664
2787
|
//#region src/host/orchestration/whereabouts.ts
|
|
1665
2788
|
const within = (inner, outer, places) => {
|
|
1666
2789
|
const byId = new Map(places.map((place) => [place.id, place]));
|
|
@@ -1881,6 +3004,29 @@ const RESULT = {
|
|
|
1881
3004
|
additionalProperties: false
|
|
1882
3005
|
}
|
|
1883
3006
|
},
|
|
3007
|
+
doubt: {
|
|
3008
|
+
type: "array",
|
|
3009
|
+
description: "Beliefs that something the character took in since speaks against, which it still holds but with more doubt: name the belief and the numbers of what speaks against it, and its confidence is lowered for you. This is the way to answer a belief that a later event contradicts, instead of revising or dropping it.",
|
|
3010
|
+
items: {
|
|
3011
|
+
type: "object",
|
|
3012
|
+
properties: {
|
|
3013
|
+
id: {
|
|
3014
|
+
type: "integer",
|
|
3015
|
+
description: "The number of the belief, as listed."
|
|
3016
|
+
},
|
|
3017
|
+
contradicted_by: {
|
|
3018
|
+
...idList,
|
|
3019
|
+
description: "The numbers of the things it took in since that speak against the belief."
|
|
3020
|
+
},
|
|
3021
|
+
text: {
|
|
3022
|
+
type: "string",
|
|
3023
|
+
description: "The belief reworded to say what is now in doubt, when its words need it; one or two sentences, and nothing but the belief: its confidence and the numbers are not part of the text."
|
|
3024
|
+
}
|
|
3025
|
+
},
|
|
3026
|
+
required: ["id", "contradicted_by"],
|
|
3027
|
+
additionalProperties: false
|
|
3028
|
+
}
|
|
3029
|
+
},
|
|
1884
3030
|
drop: {
|
|
1885
3031
|
type: "array",
|
|
1886
3032
|
description: "Beliefs to let go: settled or overturned by what came after, or merged into another.",
|
|
@@ -1921,6 +3067,10 @@ function shownOf(session, material) {
|
|
|
1921
3067
|
};
|
|
1922
3068
|
}
|
|
1923
3069
|
const rankOf = (confidence) => MEMORY_CONFIDENCES.indexOf(confidence);
|
|
3070
|
+
/** What a model writes into a belief's text when it has not put it in the fields: its confidence, importance or the numbers it rests on. */
|
|
3071
|
+
const MIXED_IN = /\((?:[^)]*\b(?:doubtful|likely|sure|importance)\b[^)]*|[^)]*\bperceptions?\s*\[?\d[^)]*)\)|\bperceptions?\s*\[\d/i;
|
|
3072
|
+
/** One step less sure, and no less than doubtful. */
|
|
3073
|
+
const lowered = (confidence) => MEMORY_CONFIDENCES[Math.max(0, rankOf(confidence) - 1)];
|
|
1924
3074
|
/**
|
|
1925
3075
|
* 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
|
|
1926
3076
|
* 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
|
|
@@ -1931,8 +3081,9 @@ function proposalProblems(proposal, shown, resolveName, tr = translator("en")) {
|
|
|
1931
3081
|
const add = proposal.add ?? [];
|
|
1932
3082
|
const revise = proposal.revise ?? [];
|
|
1933
3083
|
const drop = proposal.drop ?? [];
|
|
3084
|
+
const doubt = proposal.doubt ?? [];
|
|
1934
3085
|
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 }));
|
|
3086
|
+
if (add.length + revise.length + drop.length + doubt.length > MAX_CHANGES) problems.push(tr("at most {max} changes in one pass", { max: MAX_CHANGES }));
|
|
1936
3087
|
const cited = (ids, where) => (ids ?? []).flatMap((id) => {
|
|
1937
3088
|
const entry = shown.perceptions.get(id);
|
|
1938
3089
|
if (entry === void 0) problems.push(tr("{where}: there is no thing it took in numbered {id}", {
|
|
@@ -2012,10 +3163,11 @@ function proposalProblems(proposal, shown, resolveName, tr = translator("en")) {
|
|
|
2012
3163
|
const supports = cited(change.perceptions, where);
|
|
2013
3164
|
const against = cited(change.contradicted_by, where);
|
|
2014
3165
|
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", {
|
|
3166
|
+
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; leave it out to keep the belief as it is", {
|
|
2016
3167
|
where,
|
|
2017
3168
|
max: MAX_TEXT
|
|
2018
3169
|
}));
|
|
3170
|
+
if (change.text !== void 0 && MIXED_IN.test(change.text)) problems.push(tr("{where}: the confidence, the importance and the numbers are fields of their own, not part of the text", { where }));
|
|
2019
3171
|
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
3172
|
where,
|
|
2021
3173
|
min: 1,
|
|
@@ -2032,6 +3184,26 @@ function proposalProblems(proposal, shown, resolveName, tr = translator("en")) {
|
|
|
2032
3184
|
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
3185
|
}
|
|
2034
3186
|
});
|
|
3187
|
+
doubt.forEach((change, index) => {
|
|
3188
|
+
const where = `doubt[${index}]`;
|
|
3189
|
+
const belief = shown.beliefs.get(change.id);
|
|
3190
|
+
if (belief === void 0) {
|
|
3191
|
+
problems.push(tr("{where}: there is no belief numbered {id}", {
|
|
3192
|
+
where,
|
|
3193
|
+
id: change.id
|
|
3194
|
+
}));
|
|
3195
|
+
return;
|
|
3196
|
+
}
|
|
3197
|
+
touch(change.id, where);
|
|
3198
|
+
const against = cited(change.contradicted_by, where);
|
|
3199
|
+
if (against.length === 0) problems.push(tr("{where}: name what speaks against the belief in contradicted_by", { where }));
|
|
3200
|
+
fresh(against, belief, where);
|
|
3201
|
+
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; leave it out to keep the belief as it is", {
|
|
3202
|
+
where,
|
|
3203
|
+
max: MAX_TEXT
|
|
3204
|
+
}));
|
|
3205
|
+
if (change.text !== void 0 && MIXED_IN.test(change.text)) problems.push(tr("{where}: the confidence, the importance and the numbers are fields of their own, not part of the text", { where }));
|
|
3206
|
+
});
|
|
2035
3207
|
const dropped = new Set(drop.map((entry) => entry.id));
|
|
2036
3208
|
drop.forEach((change, index) => {
|
|
2037
3209
|
const where = `drop[${index}]`;
|
|
@@ -2057,7 +3229,7 @@ const keysOf = (names, resolveName) => (names ?? []).flatMap((name) => {
|
|
|
2057
3229
|
return key === void 0 ? [] : [key];
|
|
2058
3230
|
});
|
|
2059
3231
|
/** The edit that writes a proposal that passed. */
|
|
2060
|
-
function editOf(turn, character, proposal, resolveName) {
|
|
3232
|
+
function editOf(turn, character, proposal, resolveName, confidenceOf = () => void 0) {
|
|
2061
3233
|
const who = characterKey(character);
|
|
2062
3234
|
return {
|
|
2063
3235
|
turn,
|
|
@@ -2070,12 +3242,17 @@ function editOf(turn, character, proposal, resolveName) {
|
|
|
2070
3242
|
...belief.confidence === void 0 ? {} : { confidence: belief.confidence },
|
|
2071
3243
|
evidenceFor: belief.perceptions ?? []
|
|
2072
3244
|
})),
|
|
2073
|
-
beliefEdits:
|
|
3245
|
+
beliefEdits: [...proposal.revise ?? [], ...(proposal.doubt ?? []).map((change) => ({
|
|
3246
|
+
id: change.id,
|
|
3247
|
+
...change.text === void 0 ? {} : { text: change.text },
|
|
3248
|
+
confidence: lowered(confidenceOf(change.id) ?? "likely"),
|
|
3249
|
+
contradicted_by: change.contradicted_by
|
|
3250
|
+
}))].map((change) => ({
|
|
2074
3251
|
id: change.id,
|
|
2075
3252
|
...change.text === void 0 ? {} : { text: change.text.trim() },
|
|
2076
|
-
...change.importance
|
|
3253
|
+
..."importance" in change && change.importance !== void 0 ? { importance: change.importance } : {},
|
|
2077
3254
|
...change.confidence === void 0 ? {} : { confidence: change.confidence },
|
|
2078
|
-
evidenceFor: change.perceptions ?? [],
|
|
3255
|
+
evidenceFor: "perceptions" in change ? change.perceptions ?? [] : [],
|
|
2079
3256
|
evidenceAgainst: change.contradicted_by ?? []
|
|
2080
3257
|
})),
|
|
2081
3258
|
beliefRetractions: (proposal.drop ?? []).map((change) => change.id)
|
|
@@ -2147,14 +3324,18 @@ function memoryReflector(deps) {
|
|
|
2147
3324
|
result: RESULT,
|
|
2148
3325
|
beforeSubmit: (value) => {
|
|
2149
3326
|
const given = value;
|
|
2150
|
-
const problems = [...proposalProblems(given, shown, resolveName, tr), ...[wrongLanguage(settings.prompts.language, { beliefs: [
|
|
3327
|
+
const problems = [...proposalProblems(given, shown, resolveName, tr), ...[wrongLanguage(settings.prompts.language, { beliefs: [
|
|
3328
|
+
...given.add ?? [],
|
|
3329
|
+
...given.revise ?? [],
|
|
3330
|
+
...given.doubt ?? []
|
|
3331
|
+
].map((belief) => belief.text ?? "").join(" ") })].flatMap((problem) => problem === void 0 ? [] : [problem])];
|
|
2151
3332
|
return problems.length === 0 ? void 0 : tr("not acceptable: {problems}", { problems: problems.join("; ") });
|
|
2152
3333
|
},
|
|
2153
3334
|
maxCalls: 3
|
|
2154
3335
|
});
|
|
2155
3336
|
const reached = Math.max(...material.fresh.map((entry) => entry.perception.id));
|
|
2156
3337
|
session.transaction(() => {
|
|
2157
|
-
session.edit(editOf(job.turn, material.character, proposal, resolveName));
|
|
3338
|
+
session.edit(editOf(job.turn, material.character, proposal, resolveName, (belief) => shown.beliefs.get(belief)?.confidence));
|
|
2158
3339
|
session.metadata.setValue(CURSOR_KEY, {
|
|
2159
3340
|
...readCursor(session),
|
|
2160
3341
|
[characterKey(material.character)]: reached
|
|
@@ -2163,7 +3344,7 @@ function memoryReflector(deps) {
|
|
|
2163
3344
|
characters.push({
|
|
2164
3345
|
name: material.character.name,
|
|
2165
3346
|
added: proposal.add?.length ?? 0,
|
|
2166
|
-
revised: proposal.revise?.length ?? 0,
|
|
3347
|
+
revised: (proposal.revise?.length ?? 0) + (proposal.doubt?.length ?? 0),
|
|
2167
3348
|
dropped: proposal.drop?.length ?? 0
|
|
2168
3349
|
});
|
|
2169
3350
|
}
|
|
@@ -2257,6 +3438,6 @@ function deliverNow(session, notes, clock) {
|
|
|
2257
3438
|
}));
|
|
2258
3439
|
}
|
|
2259
3440
|
//#endregion
|
|
2260
|
-
export {
|
|
3441
|
+
export { notesOfSession as A, sameWords as B, plotProgressOf as C, parseOoc as D, MAX_OOC_ANSWER as E, TimelineError as F, readTime as G, beginTurn as H, Timelines as I, referent as J, skipTime as K, readTimeline as L, readNotes as M, observeAsPlayer as N, addToNote as O, observeSurroundings as P, pathTo as R, plotAuthorNeeded as S, AUTHORING_NEEDS as T, describeWhen as U, ClockError as V, endRound as W, languageOf as X, RESULTS as Y, translator as Z, PREVIEW_TOOL as _, readActivity as a, describePacingAdvice as b, dueReflection as c, reflectionStatus as d, whereabouts as f, toolEnabled as g, externalWithheld as h, keepRunDetail as i, putNote as j, clearNotes as k, memoryReflector as l, externalTools as m, readWithdrawn as n, readRunDetail as o, externalGiven as p, zoneOf as q, forgetRunDetails as r, recordActivity as s, deliverNow as t, recordFailure as u, createTools$1 as v, populatePlots as w, pacingAdvice as x, PLOTS_METADATA_KEY as y, defaultBoundaries as z };
|
|
2261
3442
|
|
|
2262
|
-
//# sourceMappingURL=deliver-
|
|
3443
|
+
//# sourceMappingURL=deliver-BSsDtF6X.js.map
|