@dsh-agentic-roleplay/core 0.8.1 → 0.9.0
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/{access-DtOxFKBK.js → access-CfQWbNZP.js} +4 -7
- package/lib/{authoring-tools-DNnx0Nts.js → authoring-tools-CdHlvx32.js} +2125 -152
- package/lib/authoring.js +143 -47
- package/lib/{child-D6mpkkCE.js → child-lYYeOwl2.js} +28 -51
- package/lib/client.js +611 -774
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +8 -13
- package/lib/{doctor-chat-ByDfCMeo.js → doctor-chat-hL1a61hp.js} +2 -3
- package/lib/doctor.js +6 -8
- package/lib/{gallery-D9nG3C78.js → gallery-BKh7eu80.js} +3 -4
- package/lib/{generator-r1Czm7oi.js → generator-DdZ1-sgv.js} +3 -4
- package/lib/helper.js +2 -3
- package/lib/{hooks-BQCzgggH.js → hooks-CcQj_dJo.js} +69 -97
- package/lib/images.js +4 -4
- package/lib/index.js +195 -265
- package/lib/{library-zI-2tG7h.js → library-QFL6Z_Nr.js} +9 -15
- package/lib/{lorebook-author-tools-ywaYicwd.js → lorebook-author-tools-DWBnYo1E.js} +10 -13
- package/lib/lorebook-authoring.js +5 -6
- package/lib/{narration-CnBlVure.js → narration-CjB_KwwY.js} +9 -15
- package/lib/orchestration.js +53 -64
- package/lib/{pack-jail-5EJ-WYyW.js → pack-jail-BMy6NcCY.js} +81 -788
- package/lib/{packs-Cv8hanXJ.js → packs-BREPSfHy.js} +6 -10
- package/lib/{presenter-agent-BSaMSd3G.js → presenter-agent-B49-_iUm.js} +12 -18
- package/lib/{preset-CWI3-0r1.js → preset-BqgY1Tz4.js} +5 -6
- package/lib/{preset-author-tools-BrJYa2cr.js → preset-author-tools-BB_Dcv2o.js} +12 -14
- package/lib/preset-authoring.js +6 -7
- package/lib/{presets-MwOSMMyu.js → presets-Bwnrx7p0.js} +69 -63
- package/lib/{reflection-zSaMsjKj.js → reflection-CUWG-6Qg.js} +19 -30
- package/lib/{text-BzudpQLS.js → text-CbGQhK1-.js} +9 -10
- package/lib/{turn-guard-Cv8pfHEA.js → turn-guard-Bb8Ew-1z.js} +6 -11
- package/package.json +29 -29
- package/prompts/en/checks/decide-sheet.md +1 -0
- package/prompts/en/checks/fidelity.md +7 -0
- package/prompts/en/checks/gaps.md +4 -0
- package/prompts/en/checks/notice.md +3 -0
- package/prompts/en/import/casting.md +1 -1
- package/prompts/en/import/character.md +1 -0
- package/prompts/en/import/finish-draft.md +1 -1
- package/prompts/en/import/finish-ok.md +3 -1
- package/prompts/en/import/notice-repair.md +2 -2
- package/prompts/en/import/repair-again.md +2 -2
- package/prompts/zh/checks/decide-sheet.md +1 -0
- package/prompts/zh/checks/fidelity.md +7 -0
- package/prompts/zh/checks/gaps.md +4 -0
- package/prompts/zh/checks/notice.md +3 -0
- package/prompts/zh/import/casting.md +1 -1
- package/prompts/zh/import/character.md +1 -0
- package/prompts/zh/import/finish-draft.md +1 -1
- package/prompts/zh/import/finish-ok.md +3 -1
- package/prompts/zh/import/notice-repair.md +2 -2
- package/prompts/zh/import/repair-again.md +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./access-
|
|
2
|
-
import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-
|
|
1
|
+
import "./access-CfQWbNZP.js";
|
|
2
|
+
import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-CbGQhK1-.js";
|
|
3
3
|
import { dirname, extname, join } from "node:path";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
6
6
|
import { copyFile, link, mkdir, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
7
|
-
|
|
7
|
+
// src/host/import/run.ts
|
|
8
8
|
/** The labels of a job's prompt, in the language of the import. */
|
|
9
9
|
const trOf = (ctx) => translator(languageOf(ctx.language));
|
|
10
10
|
/** Runs `work` on every item, at most `limit` at a time, and returns the results in the order of the items. */
|
|
@@ -38,8 +38,7 @@ function uniqueKey(base, taken) {
|
|
|
38
38
|
taken.add(key);
|
|
39
39
|
return key;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
//#region src/host/images/png-metadata.ts
|
|
41
|
+
// src/host/images/png-metadata.ts
|
|
43
42
|
const SIGNATURE = Buffer.from([
|
|
44
43
|
137,
|
|
45
44
|
80,
|
|
@@ -145,8 +144,7 @@ function readPngMetadata(png) {
|
|
|
145
144
|
return;
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
|
-
|
|
149
|
-
//#region src/host/images/image-files.ts
|
|
147
|
+
// src/host/images/image-files.ts
|
|
150
148
|
/** Raster formats a person may bring. Only PNG can carry its metadata inside; the others have a sidecar `<file>.json`. */
|
|
151
149
|
const MEDIA_TYPES = {
|
|
152
150
|
".png": "image/png",
|
|
@@ -180,8 +178,7 @@ async function writeImageFileMetadata(file, metadata) {
|
|
|
180
178
|
if (extname(file).toLowerCase() === ".png") await replaceAtomically(file, withPngMetadata(await readFile(file), metadata));
|
|
181
179
|
else await replaceAtomically(sidecarOf(file), `${JSON.stringify(metadata, null, 2)}\n`);
|
|
182
180
|
}
|
|
183
|
-
|
|
184
|
-
//#region src/host/images/storage.ts
|
|
181
|
+
// src/host/images/storage.ts
|
|
185
182
|
const PLURAL = {
|
|
186
183
|
character: "characters",
|
|
187
184
|
location: "locations",
|
|
@@ -280,12 +277,10 @@ async function linkOrCopy(from, to) {
|
|
|
280
277
|
await copyFile(from, to);
|
|
281
278
|
}
|
|
282
279
|
}
|
|
283
|
-
|
|
284
|
-
//#region src/shared/gallery.ts
|
|
280
|
+
// src/shared/gallery.ts
|
|
285
281
|
/** The folder of images the person brought, inside a session's `images/`. */
|
|
286
282
|
const LIBRARY_FOLDER = "library";
|
|
287
|
-
|
|
288
|
-
//#region src/host/images/library.ts
|
|
283
|
+
// src/host/images/library.ts
|
|
289
284
|
const MAGIC = [
|
|
290
285
|
{
|
|
291
286
|
type: ".png",
|
|
@@ -382,7 +377,6 @@ async function addToLibraryOnce(sessionFolder, bytes, originalName, known) {
|
|
|
382
377
|
async function addToLibrary(sessionFolder, bytes, originalName) {
|
|
383
378
|
return (await addToLibraryOnce(sessionFolder, bytes, originalName)).path;
|
|
384
379
|
}
|
|
385
|
-
//#endregion
|
|
386
380
|
export { trOf as C, slug as S, writeImageFileMetadata as _, LIBRARY_FOLDER as a, mapLimit as b, nextSceneSerial as c, sceneImagePath as d, writeImage as f, sidecarOf as g, readImageFileMetadata as h, libraryHashes as i, readImageMetadata as l, mediaTypeOf as m, addToLibraryOnce as n, entityImageDirectory as o, MEDIA_TYPES as p, imageExtensionOf as r, inheritImages as s, addToLibrary as t, referenceImagePath as u, readPngMetadata as v, uniqueKey as w, norm as x, withPngMetadata as y };
|
|
387
381
|
|
|
388
|
-
//# sourceMappingURL=library-
|
|
382
|
+
//# sourceMappingURL=library-QFL6Z_Nr.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import "./access-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { i as translator, r as languageOf } from "./text-
|
|
6
|
-
import {
|
|
1
|
+
import "./access-CfQWbNZP.js";
|
|
2
|
+
import { Zt as ImportCardError, at as deleteLorebookEntry, dt as readLorebook$1, i as contextOf, lt as loadLorebook, mt as writeLorebookEntry, ot as entriesOf, pt as updateLorebookInfo, r as MAX_PREVIEW_TEXT, ut as lorebookDirectory } from "./authoring-tools-CdHlvx32.js";
|
|
3
|
+
import { Ft as LORE_SCOPES, J as cleanText, Pt as LORE_KINDS, Q as IMPORT_FOLDER, X as partsOf, Z as withPlayer, n as createPresetFromGuidance } from "./presets-Bwnrx7p0.js";
|
|
4
|
+
import { C as trOf, S as slug, b as mapLimit, w as uniqueKey } from "./library-QFL6Z_Nr.js";
|
|
5
|
+
import { i as translator, r as languageOf } from "./text-CbGQhK1-.js";
|
|
6
|
+
import { at as shippedPromptsDirectory } from "./hooks-CcQj_dJo.js";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
9
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
10
10
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
11
|
-
|
|
11
|
+
// src/shared/lorebook-chat.ts
|
|
12
12
|
const PREFIX = "lorebook-author-";
|
|
13
13
|
/** Stable DSH chat identity for the authoring conversation of one library lorebook. */
|
|
14
14
|
function lorebookChatSessionId(name) {
|
|
@@ -25,8 +25,7 @@ function lorebookOfChat(chatSessionId) {
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
//#region src/host/import/lorebook.ts
|
|
28
|
+
// src/host/import/lorebook.ts
|
|
30
29
|
const MAX_ENTRIES = 500;
|
|
31
30
|
const BATCH_CHARS = 6e3;
|
|
32
31
|
const BATCH_ENTRIES = 8;
|
|
@@ -322,8 +321,7 @@ async function classifyEntries(ctx, book) {
|
|
|
322
321
|
}
|
|
323
322
|
return result;
|
|
324
323
|
}
|
|
325
|
-
|
|
326
|
-
//#region src/host/authoring/lorebook-author-tools.ts
|
|
324
|
+
// src/host/authoring/lorebook-author-tools.ts
|
|
327
325
|
const LOREBOOK_MUTATION_TOOLS = [
|
|
328
326
|
"write_lorebook_entry",
|
|
329
327
|
"delete_lorebook_entry",
|
|
@@ -696,7 +694,6 @@ async function lorebookApproval(exec, next, state) {
|
|
|
696
694
|
}
|
|
697
695
|
};
|
|
698
696
|
}
|
|
699
|
-
//#endregion
|
|
700
697
|
export { lorebookImportMessage as a, readLorebook as c, lorebookOfChat as d, lorebookAuthorTools as i, selectEntries as l, LorebookReader as n, pendingTargets as o, lorebookApproval as r, previewLorebook as s, LOREBOOK_UPLOAD as t, lorebookChatSessionId as u };
|
|
701
698
|
|
|
702
|
-
//# sourceMappingURL=lorebook-author-tools-
|
|
699
|
+
//# sourceMappingURL=lorebook-author-tools-DWBnYo1E.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import "./
|
|
4
|
-
import
|
|
1
|
+
import { n as limitAuthoringAgents, ut as lorebookDirectory } from "./authoring-tools-CdHlvx32.js";
|
|
2
|
+
import { t as guardAuthoringTurns } from "./turn-guard-Bb8Ew-1z.js";
|
|
3
|
+
import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-DWBnYo1E.js";
|
|
4
|
+
import "./hooks-CcQj_dJo.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { existsSync, readdirSync } from "node:fs";
|
|
7
|
-
|
|
7
|
+
// src/lorebook-authoring.ts
|
|
8
8
|
const name = "@dsh-agentic-roleplay/core/lorebook-authoring";
|
|
9
9
|
const inject = [
|
|
10
10
|
"roleplayRoot",
|
|
@@ -68,7 +68,6 @@ function apply(ctx) {
|
|
|
68
68
|
text: (context) => ctx.roleplayPrompts.text(id, languageOf(context))
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
//#endregion
|
|
72
71
|
export { apply, inject, name };
|
|
73
72
|
|
|
74
73
|
//# sourceMappingURL=lorebook-authoring.js.map
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import "./access-
|
|
1
|
+
import "./access-CfQWbNZP.js";
|
|
2
2
|
import { basename, dirname, join } from "node:path";
|
|
3
3
|
import { chmodSync, existsSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { chmod, mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
|
-
|
|
6
|
+
// ../dsh-roleplay-model/src/clock.ts
|
|
7
7
|
/**
|
|
8
8
|
* How the story's time passes: `simulated` moves only when the story does (the game master says how
|
|
9
9
|
* long things take and may skip ahead), `real` follows the wall clock.
|
|
10
10
|
*/
|
|
11
11
|
const CLOCK_MODES = ["simulated", "real"];
|
|
12
|
-
|
|
13
|
-
//#region src/shared/decisions.ts
|
|
12
|
+
// src/shared/decisions.ts
|
|
14
13
|
/** The places where a language model's closed-choice judgement can be given to a decision model instead, or, for the gates, a check can be made at all. */
|
|
15
14
|
const DECISION_SITES = [
|
|
16
15
|
"triggers",
|
|
@@ -54,8 +53,7 @@ const emptyStats = (since) => ({
|
|
|
54
53
|
since,
|
|
55
54
|
sites: Object.fromEntries(DECISION_SITES.map((site) => [site, emptySiteStats()]))
|
|
56
55
|
});
|
|
57
|
-
|
|
58
|
-
//#region src/shared/rules.ts
|
|
56
|
+
// src/shared/rules.ts
|
|
59
57
|
/** The key under which a session keeps the rules of its world, which it copies at the start so that it stays whole without the world's files. */
|
|
60
58
|
const WORLD_RULES_KEY = "rules";
|
|
61
59
|
/** The longest text of the player's own rules. */
|
|
@@ -186,7 +184,7 @@ const SETTINGS_SPEC = {
|
|
|
186
184
|
judgedPerTurn: integer(0, 5, 2)
|
|
187
185
|
},
|
|
188
186
|
decisions: {
|
|
189
|
-
triggers: choice(DECISION_MODES, "
|
|
187
|
+
triggers: choice(DECISION_MODES, "hybrid"),
|
|
190
188
|
reflection: choice(DECISION_MODES, "llm"),
|
|
191
189
|
agency: choice(GATE_MODES, "off"),
|
|
192
190
|
refusal: choice(GATE_MODES, "off"),
|
|
@@ -321,8 +319,7 @@ function parseSettings(value) {
|
|
|
321
319
|
value: parsed
|
|
322
320
|
};
|
|
323
321
|
}
|
|
324
|
-
|
|
325
|
-
//#region src/host/atomic-write.ts
|
|
322
|
+
// src/host/atomic-write.ts
|
|
326
323
|
/**
|
|
327
324
|
* Replaces a file in one step: the data goes to a temporary file in the same folder and is renamed over the file, so an interruption leaves the old file or the new one,
|
|
328
325
|
* never half of either. Every writer of a file someone else may read at the same time goes through here.
|
|
@@ -366,8 +363,7 @@ function atomicWriteSync(file, data) {
|
|
|
366
363
|
throw error;
|
|
367
364
|
}
|
|
368
365
|
}
|
|
369
|
-
|
|
370
|
-
//#region src/host/sessions/settings.ts
|
|
366
|
+
// src/host/sessions/settings.ts
|
|
371
367
|
const SETTINGS_FILE = "settings.json";
|
|
372
368
|
const known = /* @__PURE__ */ new Map();
|
|
373
369
|
let childReasoning = () => "";
|
|
@@ -456,8 +452,7 @@ function loadedSettings(folder, problem) {
|
|
|
456
452
|
return value;
|
|
457
453
|
}
|
|
458
454
|
}
|
|
459
|
-
|
|
460
|
-
//#region src/shared/narration.ts
|
|
455
|
+
// src/shared/narration.ts
|
|
461
456
|
const OPEN = "<roleplay-output>";
|
|
462
457
|
const CLOSE = "</roleplay-output>";
|
|
463
458
|
const PREVIEW_OPEN = "<roleplay-preview>";
|
|
@@ -499,7 +494,6 @@ function decodeOutput(text) {
|
|
|
499
494
|
return;
|
|
500
495
|
}
|
|
501
496
|
}
|
|
502
|
-
//#endregion
|
|
503
497
|
export { DECISION_SITES as _, liveSettings as a, writeSettings as c, DEFAULT_SETTINGS as d, SETTINGS_SPEC as f, rulesOf as g, WORLD_RULES_KEY as h, InvalidSettingsError as i, atomicWrite as l, parseSwitchboard as m, encodeOutput as n, readSettings as o, parseSettings as p, encodePreview as r, useChildReasoning as s, decodeOutput as t, atomicWriteJson as u, GATE_SITES as v, emptyStats as y };
|
|
504
498
|
|
|
505
|
-
//# sourceMappingURL=narration-
|
|
499
|
+
//# sourceMappingURL=narration-CjB_KwwY.js.map
|
package/lib/orchestration.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { a as chatSessionId, o as roleplaySessionOf, t as promptFor } from "./access-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import {
|
|
6
|
-
import { i as translator, r as languageOf } from "./text-
|
|
7
|
-
import { a as
|
|
8
|
-
import { S as slug, t as addToLibrary, w as uniqueKey } from "./library-
|
|
9
|
-
import { _ as API_PREFIX } from "./packs-
|
|
10
|
-
import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-
|
|
11
|
-
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-
|
|
1
|
+
import { a as chatSessionId, o as roleplaySessionOf, t as promptFor } from "./access-CfQWbNZP.js";
|
|
2
|
+
import { D as describeWhen, G as commandsOf, O as zoneOf, R as wrongLanguage, T as ClockError, U as COMMANDS_KEY, W as commandFlagKey, c as record, f as MAX_OOC_ANSWER, k as RESULTS, l as characterRunner, mt as AUTHORING_NEEDS, n as installHooks, o as PREVIEW_TOOL, ot as shippedText, p as storesOf, r as externalGiven, s as createTools$1, u as toolEnabled, ut as ReflectionRefusedError, v as readVerdicts, y as writeVerdicts } from "./hooks-CcQj_dJo.js";
|
|
3
|
+
import { a as childTrace, c as runChild, h as currentTurn, n as childModel, r as childSampling, v as estimateAnswer, y as tokensOf } from "./child-lYYeOwl2.js";
|
|
4
|
+
import { _ as referent, a as whereabouts, g as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-CUWG-6Qg.js";
|
|
5
|
+
import { B as noAt, H as yesAt, I as announceProblem, L as askYesNo, Rt as INTENT_STATUSES, V as routeVerdicts, m as STANDING_PROMPT, z as modeFor } from "./presets-Bwnrx7p0.js";
|
|
6
|
+
import { i as translator, r as languageOf } from "./text-CbGQhK1-.js";
|
|
7
|
+
import { a as liveSettings, n as encodeOutput, v as GATE_SITES } from "./narration-CjB_KwwY.js";
|
|
8
|
+
import { S as slug, t as addToLibrary, w as uniqueKey } from "./library-QFL6Z_Nr.js";
|
|
9
|
+
import { _ as API_PREFIX } from "./packs-BREPSfHy.js";
|
|
10
|
+
import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-BKh7eu80.js";
|
|
11
|
+
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-B49-_iUm.js";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { existsSync } from "node:fs";
|
|
14
14
|
import { readdir } from "node:fs/promises";
|
|
15
15
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
16
16
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
17
17
|
import { InvalidEditError, characterKey, createDiceTools, createTools, dayPart, describeDuration, describeHolder, describeInstant, describeValue, itemKey, judgedStatements, lintWorld, localTime, locationKey, mentioned, parseRecordsEdit, rollForCheck, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
18
|
-
|
|
18
|
+
// src/host/tools/resource-hint.ts
|
|
19
19
|
/** The name DSH's MCP resource plugin gives the prompt paragraph it adds for every agent; a section of the same name in an agent's scope replaces it. */
|
|
20
20
|
const RESOURCE_HINT_SECTION = "mcp-resource-servers";
|
|
21
21
|
const RESOURCE_TOOLS = [
|
|
@@ -42,8 +42,7 @@ function resourceHint(visible, registered, tr) {
|
|
|
42
42
|
servers: JSON.stringify(servers)
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
//#region src/host/memory/tags.ts
|
|
45
|
+
// src/host/memory/tags.ts
|
|
47
46
|
const MIN_FUZZY_LENGTH = 5;
|
|
48
47
|
const plain = (tag) => tag.normalize("NFKC").trim().toLowerCase().replace(/[\s_]+/g, "-");
|
|
49
48
|
/** What two spellings of one word share: separators and a plural ending do not make a different tag. */
|
|
@@ -81,8 +80,7 @@ function canonicalTags(known, tags) {
|
|
|
81
80
|
});
|
|
82
81
|
return [...new Set(canonical)];
|
|
83
82
|
}
|
|
84
|
-
|
|
85
|
-
//#region src/host/orchestration/committer.ts
|
|
83
|
+
// src/host/orchestration/committer.ts
|
|
86
84
|
/** How many of the tags in use a brief lists. */
|
|
87
85
|
const TAGS_LISTED = 60;
|
|
88
86
|
/** What the keeper reads back by default: the parts of the records its edits write. */
|
|
@@ -329,8 +327,7 @@ function suggestionProblems(lines, wanted) {
|
|
|
329
327
|
}
|
|
330
328
|
/** One short line each: whitespace is collapsed. */
|
|
331
329
|
const tidySuggestions = (lines) => lines.map((line) => line.trim().replace(/\s+/g, " "));
|
|
332
|
-
|
|
333
|
-
//#region src/host/orchestration/suggester.ts
|
|
330
|
+
// src/host/orchestration/suggester.ts
|
|
334
331
|
const RESULT$3 = {
|
|
335
332
|
type: "object",
|
|
336
333
|
properties: { options: {
|
|
@@ -379,8 +376,7 @@ function suggestionWriter(deps) {
|
|
|
379
376
|
})).options;
|
|
380
377
|
} };
|
|
381
378
|
}
|
|
382
|
-
|
|
383
|
-
//#region src/host/triggers/judge.ts
|
|
379
|
+
// src/host/triggers/judge.ts
|
|
384
380
|
const RESULT$2 = {
|
|
385
381
|
type: "object",
|
|
386
382
|
properties: { verdicts: {
|
|
@@ -490,7 +486,7 @@ function triggerJudge(deps) {
|
|
|
490
486
|
return new Map(keys.map((key) => [key, asked.get(`s${key}`)]));
|
|
491
487
|
};
|
|
492
488
|
const routed = await routeVerdicts({
|
|
493
|
-
mode: settings.decisions.triggers,
|
|
489
|
+
mode: modeFor(settings.decisions.triggers, deps.decisions?.()),
|
|
494
490
|
yesAt: yesAt(settings.decisions.confidence),
|
|
495
491
|
noAt: noAt(settings.decisions.confidence),
|
|
496
492
|
turn: job.turn,
|
|
@@ -589,8 +585,7 @@ function ruleChecks(deps) {
|
|
|
589
585
|
return found.map((key) => rules[Number(key.slice(4))]);
|
|
590
586
|
} };
|
|
591
587
|
}
|
|
592
|
-
|
|
593
|
-
//#region src/host/decisions/gates.ts
|
|
588
|
+
// src/host/decisions/gates.ts
|
|
594
589
|
/**
|
|
595
590
|
* How far below the threshold a probability may fall and still be not sure. A decision model gives a rare fault a low probability even when it
|
|
596
591
|
* sees it (measured: faults between 0.3 and 0.9, clean passages below 0.4), so a gate's cut is its own threshold, not the chat's confidence.
|
|
@@ -714,8 +709,7 @@ async function secretFindings(job, decisions, service, seen, signal, say) {
|
|
|
714
709
|
message: `the output may give away what ${job.player === "" ? "the player's character" : job.player} does not know yet (${titles.join("; ")}): show only what can be seen or heard, and let the rest be learned in the story; if this is meant to be revealed now, deliver it again unchanged`
|
|
715
710
|
}];
|
|
716
711
|
}
|
|
717
|
-
|
|
718
|
-
//#region src/host/factions/strategist.ts
|
|
712
|
+
// src/host/factions/strategist.ts
|
|
719
713
|
const LAST_KEY = "strategy.last";
|
|
720
714
|
const DAY_MS = 864e5;
|
|
721
715
|
/** Rounds numbered from here belong to what organisations did, as off-stage rounds have their own range. */
|
|
@@ -921,8 +915,7 @@ function factionStrategist(deps) {
|
|
|
921
915
|
return { acted };
|
|
922
916
|
} };
|
|
923
917
|
}
|
|
924
|
-
|
|
925
|
-
//#region src/host/authoring/author-agent.ts
|
|
918
|
+
// src/host/authoring/author-agent.ts
|
|
926
919
|
/** How many calls of the tools of other plugins the author may make on top of its own budget. */
|
|
927
920
|
const EXTERNAL_CALLS = 10;
|
|
928
921
|
/** A made-up thing in one edit: its name, description and the handful of fields a character, place or item carries. */
|
|
@@ -932,6 +925,16 @@ const THING_TEXT_CHARS = 300;
|
|
|
932
925
|
const FIT_TEXTS = 6;
|
|
933
926
|
const FIT_TEXT_CHARS = 200;
|
|
934
927
|
const editEstimate = (things, texts, chars, language) => estimateAnswer(Array.from({ length: Math.max(1, things) * texts }, () => chars), language);
|
|
928
|
+
/** The keys of the people, places and things an edit makes that this run made already: made once, they are connected, not made again. */
|
|
929
|
+
function madeAgain(args, work) {
|
|
930
|
+
const made = new Set(work.created.map((entry) => entry.key));
|
|
931
|
+
const keys = [
|
|
932
|
+
"characters",
|
|
933
|
+
"places",
|
|
934
|
+
"items"
|
|
935
|
+
].flatMap((field) => (Array.isArray(args[field]) ? args[field] : []).flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry.key === "string" ? [entry.key] : []));
|
|
936
|
+
return [...new Set(keys.filter((key) => made.has(key)))];
|
|
937
|
+
}
|
|
935
938
|
/** A person made up without a place joins the scene: the place of the player's character, which is where the author is told to put them. */
|
|
936
939
|
function placedWhereThePlayerIs(args, store) {
|
|
937
940
|
if (!Array.isArray(args["characters"])) return args;
|
|
@@ -1004,6 +1007,8 @@ function authorTools(job, work, mode, limits) {
|
|
|
1004
1007
|
]
|
|
1005
1008
|
];
|
|
1006
1009
|
for (const [noun, now, already] of allowed) if (now > 0 && already + now > limits.perTurn) throw new Error(`this edit makes ${now} new ${noun}${now === 1 ? "" : "s"} and ${already} ${already === 1 ? "was" : "were"} already made this turn, which would pass the ${limits.perTurn} this chat allows per turn for each kind: make fewer, or none`);
|
|
1010
|
+
const again = madeAgain(args, work);
|
|
1011
|
+
if (again.length > 0) throw new Error(`${again.join(", ")} ${again.length === 1 ? "is" : "are"} already made in this run: do not make ${again.length === 1 ? "it" : "them"} again. A later edit_world call leaves ${again.length === 1 ? "it" : "them"} out and only adds what is still missing (relationships, ways, moves); when nothing is missing, call submit_result with outcome created.`);
|
|
1007
1012
|
const result = await tool.execute(placedWhereThePlayerIs(args, job.store), exec);
|
|
1008
1013
|
for (const key of result.character_keys ?? []) work.created.push({
|
|
1009
1014
|
kind: "character",
|
|
@@ -1284,12 +1289,10 @@ function worldAuthor(deps) {
|
|
|
1284
1289
|
}
|
|
1285
1290
|
};
|
|
1286
1291
|
}
|
|
1287
|
-
|
|
1288
|
-
//#region src/host/orchestration/prompt.ts
|
|
1292
|
+
// src/host/orchestration/prompt.ts
|
|
1289
1293
|
const PROTOCOL_SECTION = "roleplay:protocol";
|
|
1290
1294
|
const PERSONA_SECTION = "roleplay:persona";
|
|
1291
|
-
|
|
1292
|
-
//#region src/host/dice/describe.ts
|
|
1295
|
+
// src/host/dice/describe.ts
|
|
1293
1296
|
const sentenceBody = (value) => {
|
|
1294
1297
|
let end = value.length;
|
|
1295
1298
|
while (end > 0 && (value[end - 1] === "." || /\s/u.test(value[end - 1]))) end -= 1;
|
|
@@ -1313,8 +1316,7 @@ function describeChecks(checks, tr) {
|
|
|
1313
1316
|
});
|
|
1314
1317
|
return [tr("The checks of this story:"), ...lines].join("\n");
|
|
1315
1318
|
}
|
|
1316
|
-
|
|
1317
|
-
//#region src/host/orchestration/check-tool.ts
|
|
1319
|
+
// src/host/orchestration/check-tool.ts
|
|
1318
1320
|
const CHECK_NARRATE_TOOL = "roll_and_narrate";
|
|
1319
1321
|
const BRANCHES = [
|
|
1320
1322
|
["succeeded", "on_success"],
|
|
@@ -1480,8 +1482,7 @@ function createCheckNarrateTool(deps) {
|
|
|
1480
1482
|
}
|
|
1481
1483
|
});
|
|
1482
1484
|
}
|
|
1483
|
-
|
|
1484
|
-
//#region src/host/memory/embedding-index.ts
|
|
1485
|
+
// src/host/memory/embedding-index.ts
|
|
1485
1486
|
const BATCH = 32;
|
|
1486
1487
|
/**
|
|
1487
1488
|
* Keeps the vectors of a chat's texts: embeds what has none yet, and gives the vector of a moment to
|
|
@@ -1571,8 +1572,7 @@ var EmbeddingIndex = class {
|
|
|
1571
1572
|
this.deps.problem(message);
|
|
1572
1573
|
}
|
|
1573
1574
|
};
|
|
1574
|
-
|
|
1575
|
-
//#region src/host/memory/rerank-memories.ts
|
|
1575
|
+
// src/host/memory/rerank-memories.ts
|
|
1576
1576
|
/**
|
|
1577
1577
|
* Judges the pool of memories a recall over-retrieved with a reranking service, by reading the
|
|
1578
1578
|
* situation and each memory together. Without a service it has nothing to judge and says so, and the
|
|
@@ -1602,8 +1602,7 @@ function rerankMemories(deps) {
|
|
|
1602
1602
|
}
|
|
1603
1603
|
};
|
|
1604
1604
|
}
|
|
1605
|
-
|
|
1606
|
-
//#region src/host/orchestration/suggestion-fallback.ts
|
|
1605
|
+
// src/host/orchestration/suggestion-fallback.ts
|
|
1607
1606
|
/**
|
|
1608
1607
|
* Lines made from the story's own data when the suggester could not make any, so the player is never left with an empty tray:
|
|
1609
1608
|
* someone to talk to, a way out, a thing to look at, then plain standbys. No model is asked.
|
|
@@ -1632,8 +1631,7 @@ function fallbackSuggestions(store, count) {
|
|
|
1632
1631
|
const lines = tidySuggestions(picked).map((line) => line.length > 200 ? `${line.slice(0, 199)}…` : line);
|
|
1633
1632
|
return suggestionProblems(lines, count).length === 0 ? lines : [];
|
|
1634
1633
|
}
|
|
1635
|
-
|
|
1636
|
-
//#region src/host/orchestration/after-turn.ts
|
|
1634
|
+
// src/host/orchestration/after-turn.ts
|
|
1637
1635
|
/** Something made up that has waited this many turns is fitted into the world even if few are waiting. */
|
|
1638
1636
|
const STALE_AFTER_TURNS = 4;
|
|
1639
1637
|
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
@@ -1779,8 +1777,7 @@ var AfterTurnJobs = class {
|
|
|
1779
1777
|
}));
|
|
1780
1778
|
}
|
|
1781
1779
|
};
|
|
1782
|
-
|
|
1783
|
-
//#region src/host/orchestration/turn-rules.ts
|
|
1780
|
+
// src/host/orchestration/turn-rules.ts
|
|
1784
1781
|
/** Whether the game master still has to judge the player's action. */
|
|
1785
1782
|
function judgeDue(state) {
|
|
1786
1783
|
return state.judgeWanted === true && state.phase === "idle" && state.ooc === void 0 && state.judgement === void 0;
|
|
@@ -1949,8 +1946,7 @@ function decisions(state) {
|
|
|
1949
1946
|
}
|
|
1950
1947
|
return decided;
|
|
1951
1948
|
}
|
|
1952
|
-
|
|
1953
|
-
//#region src/host/orchestration/character-attempt.ts
|
|
1949
|
+
// src/host/orchestration/character-attempt.ts
|
|
1954
1950
|
/** Every character acts at the same time; one that fails or answers badly is reported, not fatal. */
|
|
1955
1951
|
async function askCharacters(deps, owner, number, keys, cast, state, run, signal, away = false) {
|
|
1956
1952
|
const { store, boundaries } = deps;
|
|
@@ -2042,8 +2038,7 @@ async function askCharacters(deps, owner, number, keys, cast, state, run, signal
|
|
|
2042
2038
|
failures: answers.filter((answer) => "reason" in answer)
|
|
2043
2039
|
};
|
|
2044
2040
|
}
|
|
2045
|
-
|
|
2046
|
-
//#region src/host/orchestration/round-record.ts
|
|
2041
|
+
// src/host/orchestration/round-record.ts
|
|
2047
2042
|
/** Records the game master's decisions as a finished round: what the characters did and said, what changed in the story, and the round queued for the keeper. `fire` runs the triggers the round may have made true. */
|
|
2048
2043
|
function recordRound(store, owner, state, fire) {
|
|
2049
2044
|
const decided = decisions(state);
|
|
@@ -2191,8 +2186,7 @@ function recordRound(store, owner, state, fire) {
|
|
|
2191
2186
|
}] : [])
|
|
2192
2187
|
};
|
|
2193
2188
|
}
|
|
2194
|
-
|
|
2195
|
-
//#region src/host/orchestration/question-request.ts
|
|
2189
|
+
// src/host/orchestration/question-request.ts
|
|
2196
2190
|
/** What the player's character is given to answer a question with: the same as a character is given to act, with the question as the moment. */
|
|
2197
2191
|
async function questionRequest(boundaries, store, owner, question, signal) {
|
|
2198
2192
|
const cast = store.cast();
|
|
@@ -2231,8 +2225,7 @@ async function questionRequest(boundaries, store, owner, question, signal) {
|
|
|
2231
2225
|
...memories.length === 0 ? {} : { memories }
|
|
2232
2226
|
};
|
|
2233
2227
|
}
|
|
2234
|
-
|
|
2235
|
-
//#region src/host/orchestration/world-making.ts
|
|
2228
|
+
// src/host/orchestration/world-making.ts
|
|
2236
2229
|
/**
|
|
2237
2230
|
* The game master asks for something to be made up (a place the story has gone to, someone who has
|
|
2238
2231
|
* joined): the world author decides whether the story genuinely needs it, and makes it or says why not.
|
|
@@ -2304,8 +2297,7 @@ function introduceThing(store, state, owner, input) {
|
|
|
2304
2297
|
where: "heldBy" in placed ? `held by ${placed.heldBy}` : "inside" in placed ? `inside ${placed.inside}` : `at ${placed.at.location}`
|
|
2305
2298
|
};
|
|
2306
2299
|
}
|
|
2307
|
-
|
|
2308
|
-
//#region src/host/orchestration/turn-text.ts
|
|
2300
|
+
// src/host/orchestration/turn-text.ts
|
|
2309
2301
|
/**
|
|
2310
2302
|
* A model sometimes sends who speaks as a segment of its own (an utterance with no character whose text is the character's key or name) followed by the words with no
|
|
2311
2303
|
* character either. When the label is exactly a character of the scene, the label is folded into the words that follow it.
|
|
@@ -2388,8 +2380,7 @@ function checkedOutput(narrationChecker, language, state, segments, silent) {
|
|
|
2388
2380
|
repaired: true
|
|
2389
2381
|
};
|
|
2390
2382
|
}
|
|
2391
|
-
|
|
2392
|
-
//#region src/host/dice/view.ts
|
|
2383
|
+
// src/host/dice/view.ts
|
|
2393
2384
|
const sign = (value) => value >= 0 ? `+${value}` : String(value);
|
|
2394
2385
|
/** A roll as the player reads it: what it was for, what fell, what it came to and what the world's check made of it. */
|
|
2395
2386
|
function rollView(roll) {
|
|
@@ -2488,8 +2479,7 @@ async function runOffScene(deps, owner, state, store, due, limit) {
|
|
|
2488
2479
|
}
|
|
2489
2480
|
}
|
|
2490
2481
|
}
|
|
2491
|
-
|
|
2492
|
-
//#region src/host/orchestration/turn-engine.ts
|
|
2482
|
+
// src/host/orchestration/turn-engine.ts
|
|
2493
2483
|
const MAX_OBJECTIONS = 3;
|
|
2494
2484
|
/** The most a single round may be said to take: a day. A longer time passing is skipped with `advanceTime`. */
|
|
2495
2485
|
const MAX_ROUND_SECONDS = 86400;
|
|
@@ -3299,8 +3289,7 @@ var TurnEngine = class {
|
|
|
3299
3289
|
return output;
|
|
3300
3290
|
}
|
|
3301
3291
|
};
|
|
3302
|
-
|
|
3303
|
-
//#region src/host/images/jobs.ts
|
|
3292
|
+
// src/host/images/jobs.ts
|
|
3304
3293
|
/** The same service, whose requests stand where the job's do unless a call says otherwise. */
|
|
3305
3294
|
function withPriority(service, priority, highRes) {
|
|
3306
3295
|
return Object.create(service, { generate: { value: (prompt, options) => service.generate(prompt, {
|
|
@@ -3519,8 +3508,7 @@ var ImageJobs = class {
|
|
|
3519
3508
|
return `${id}/${node}`;
|
|
3520
3509
|
}
|
|
3521
3510
|
};
|
|
3522
|
-
|
|
3523
|
-
//#region src/orchestration.ts
|
|
3511
|
+
// src/orchestration.ts
|
|
3524
3512
|
const WORKING_DIRECTORY_CONTEXT = "working-directory:current";
|
|
3525
3513
|
const name = "@dsh-agentic-roleplay/core/orchestration";
|
|
3526
3514
|
/**
|
|
@@ -3597,11 +3585,13 @@ function apply(ctx) {
|
|
|
3597
3585
|
const id = roleplaySessionOf(agentSessionId);
|
|
3598
3586
|
const agent = ctx.agents.get(SessionId(agentSessionId));
|
|
3599
3587
|
if (id === void 0 || agent === void 0) return void 0;
|
|
3588
|
+
const session = ctx.roleplayState.openSession(sessionsDir(), id);
|
|
3600
3589
|
return {
|
|
3601
|
-
session
|
|
3590
|
+
session,
|
|
3602
3591
|
turn: currentTurn(agent),
|
|
3603
3592
|
policy: liveSettings(sessionFolder(sessionsDir(), id)).memory,
|
|
3604
|
-
queryVector: (text, signal) => index.queryVector(agentSessionId, text, signal)
|
|
3593
|
+
queryVector: (text, signal) => index.queryVector(agentSessionId, text, signal),
|
|
3594
|
+
engineVariables: () => commandsOf(session.metadata.getValue(COMMANDS_KEY)).map(commandFlagKey)
|
|
3605
3595
|
};
|
|
3606
3596
|
}), "roleplay: state tools");
|
|
3607
3597
|
const settingsOf = (context) => {
|
|
@@ -3765,7 +3755,6 @@ function apply(ctx) {
|
|
|
3765
3755
|
optionalTools: [...createDiceTools(diceLink), createCheckNarrateTool(toolDeps)]
|
|
3766
3756
|
});
|
|
3767
3757
|
}
|
|
3768
|
-
//#endregion
|
|
3769
3758
|
export { apply, inject, name };
|
|
3770
3759
|
|
|
3771
3760
|
//# sourceMappingURL=orchestration.js.map
|