@dsh-agentic-roleplay/core 0.12.1 → 0.12.3
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/cordis.patch.yml +108 -0
- package/lib/{access-DifaiHrI.js → access-Csp80TFX.js} +2 -2
- package/lib/{authoring-tools-VOaXzr_R.js → authoring-tools-hacA5fG-.js} +1910 -1853
- package/lib/authoring.js +42 -34
- package/lib/{child-DzZ-aI6k.js → child-DTdY14S9.js} +45 -6
- package/lib/client.js +830 -571
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/{dev-context-Bdm-eVer.js → dev-context-Cgv_wZbG.js} +12 -2
- package/lib/doctor.js +5 -4
- package/lib/{gallery-Ctz-UoFk.js → gallery-BNg0rPTp.js} +3 -3
- package/lib/{generator-Cv6WWmZT.js → generator-9-5at9cZ.js} +2 -2
- package/lib/helper.js +4 -10
- package/lib/{hooks-BdR3mBeM.js → hooks-DlrFO4aQ.js} +216 -45
- package/lib/images.js +4 -4
- package/lib/index.js +67 -45
- package/lib/{jail-Cp4zEfip.js → jail-DVbPSC0R.js} +2 -2
- package/lib/{library-BU2A_Dx8.js → library-DTxakw0z.js} +2 -2
- package/lib/{lorebook-author-tools-DUKcQu8P.js → lorebook-author-tools-dupq-kb_.js} +6 -6
- package/lib/lorebook-authoring.js +7 -6
- package/lib/{narration-CDsJ5wxH.js → narration--K2XVIHI.js} +2 -2
- package/lib/orchestration.js +12 -12
- package/lib/{pack-jail-CzHQu0n3.js → pack-jail-Bq0fzKi4.js} +43 -16
- package/lib/{packs-BZ-45J4-.js → packs-D-7EU3yU.js} +2 -2
- package/lib/{presenter-agent-C2ZkoxZu.js → presenter-agent-vFOxIuWv.js} +6 -6
- package/lib/{preset-BPnRPW-1.js → preset-RHcOG55T.js} +4 -4
- package/lib/{preset-author-tools-DBqPwn-o.js → preset-author-tools-Dwxnpv6V.js} +6 -6
- package/lib/preset-authoring.js +7 -6
- package/lib/{reflection-Cuy0YLv0.js → reflection-DibpEUQK.js} +7 -7
- package/lib/{serial-BZNeK57v.js → serial-CDGoXYh-.js} +1317 -1276
- package/lib/{turn-guard-xaFxYc1T.js → turn-guard-DDxikrq7.js} +3 -3
- package/package.json +4 -3
package/lib/authoring.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as guardAuthoringTurns } from "./turn-guard-
|
|
3
|
-
import { t as silenceHarnessDevContext } from "./dev-context-
|
|
4
|
-
import { B as deleteTriggerDocument, D as editWorldPlots, G as parseVariablesEdit, H as writeTriggerDocument, K as parseDiceEdit, M as readWorldEditor, O as editWorldRelation, Q as translateTools, U as parseCalendarEdit, V as readTriggerDocuments, X as presetTools, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, f as editCalendar, g as editVariables, i as checkWorldPack, l as deleteAuthoredEntity, m as editDice, nt as finishUpdate, o as listWorldPacks, p as editCommands, q as parseCommandsEdit, r as registerPackJail, rt as pendingUpdate, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument } from "./pack-jail-
|
|
1
|
+
import { $ as checkWorld, A as loadWorldParts, At as UPDATE_FOLDER, C as cardChanges, D as worldFieldChanges, E as pictureChange, F as editsSince, Ft as readSource, It as COMMANDS_FILE_NAME, M as CHECK_COMMANDS, N as CHECK_COMMAND_DESCRIPTIONS, Nt as cardTools, O as editWorldInfo, Pt as entitiesByPiece, S as addressChanges, St as DICE_FILE_NAME, T as matchPieces, Tt as CALENDAR_FILE_NAME, Xt as authoredWorldOf, b as CHECKS, j as loadCardEvidence, k as readWorldInfo, l as importTools, n as limitAuthoringAgents, o as contextOf, p as isReviewing, s as importHooks, v as checkImported, w as diffText, x as runChecks, y as presentReport } from "./authoring-tools-hacA5fG-.js";
|
|
2
|
+
import { t as guardAuthoringTurns } from "./turn-guard-DDxikrq7.js";
|
|
3
|
+
import { n as silenceRuntimeContext, t as silenceHarnessDevContext } from "./dev-context-Cgv_wZbG.js";
|
|
4
|
+
import { B as deleteTriggerDocument, D as editWorldPlots, G as parseVariablesEdit, H as writeTriggerDocument, K as parseDiceEdit, M as readWorldEditor, O as editWorldRelation, Q as translateTools, U as parseCalendarEdit, V as readTriggerDocuments, X as presetTools, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, f as editCalendar, g as editVariables, i as checkWorldPack, l as deleteAuthoredEntity, m as editDice, nt as finishUpdate, o as listWorldPacks, p as editCommands, q as parseCommandsEdit, r as registerPackJail, rt as pendingUpdate, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument } from "./pack-jail-Bq0fzKi4.js";
|
|
5
5
|
import { i as translator, r as languageOf } from "./text-Dfv8S8eq.js";
|
|
6
|
-
import { $ as deleteWorldPrompt,
|
|
7
|
-
import { B as parsePlotsFile,
|
|
8
|
-
import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-
|
|
9
|
-
import "./access-
|
|
6
|
+
import { $ as deleteWorldPrompt, Ct as IMPORT_FOLDER, Et as PICTURE_FILE, F as parseWorldInfoEdit, It as parseRelationEdit, Q as PROSE_PROMPTS, Wt as VARIABLES_FILE_NAME, et as listWorldPrompts, jt as InvalidEditProblems, nt as writeWorldPrompt, tt as readWorldPrompt } from "./serial-CDGoXYh-.js";
|
|
7
|
+
import { B as parsePlotsFile, at as shippedPromptsDirectory, ht as registerCommands, q as formatIssue } from "./hooks-DlrFO4aQ.js";
|
|
8
|
+
import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-D-7EU3yU.js";
|
|
9
|
+
import "./access-Csp80TFX.js";
|
|
10
10
|
import { join, relative } from "node:path";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
import { readFile, readdir } from "node:fs/promises";
|
|
@@ -1323,7 +1323,7 @@ function checkTools(reader, judging) {
|
|
|
1323
1323
|
})
|
|
1324
1324
|
];
|
|
1325
1325
|
}
|
|
1326
|
-
// src/host/checks/
|
|
1326
|
+
// src/host/checks/commands.ts
|
|
1327
1327
|
/** The tool each kit is run with, for the notice of a check command. */
|
|
1328
1328
|
const KIT_TOOLS = {
|
|
1329
1329
|
consistency: "check_world",
|
|
@@ -1331,34 +1331,41 @@ const KIT_TOOLS = {
|
|
|
1331
1331
|
quality: "check_quality",
|
|
1332
1332
|
playability: "check_play"
|
|
1333
1333
|
};
|
|
1334
|
-
/**
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1334
|
+
/**
|
|
1335
|
+
* The check commands (`/check`, `/check-world`, ...) of a world authoring chat. Running one tells the assistant which kits to run and what to do with what they find, and what the person
|
|
1336
|
+
* added after the name (`deep` lets a model judge too) is passed on as it was typed.
|
|
1337
|
+
*/
|
|
1338
|
+
function checkCommands(ctx, prompting) {
|
|
1339
|
+
registerCommands(ctx, Object.entries(CHECK_COMMANDS).map(([name, kits]) => ({
|
|
1340
|
+
name,
|
|
1341
|
+
description: CHECK_COMMAND_DESCRIPTIONS[name] ?? name,
|
|
1342
|
+
hint: "[deep] [what to look at]",
|
|
1343
|
+
recordInput: false,
|
|
1344
|
+
handler: ({ agent, rawInput }) => {
|
|
1345
|
+
const world = authoredWorldOf(agent.session.id);
|
|
1346
|
+
if (world === void 0 || agent.session.header.origin === "subagent") return {
|
|
1347
|
+
kind: "error",
|
|
1348
|
+
text: `/${name} runs in the authoring chat of a world`
|
|
1349
|
+
};
|
|
1350
|
+
const request = rawInput.trim();
|
|
1351
|
+
const notice = prompting.prompts().text("checks/notice", prompting.languages().get(world), {
|
|
1352
|
+
command: `/${name}`,
|
|
1353
|
+
tools: kits.map((kit) => KIT_TOOLS[kit]).join(", "),
|
|
1354
|
+
request: request === "" ? "-" : request
|
|
1355
|
+
});
|
|
1356
|
+
agent.followup(createUserMessage({
|
|
1354
1357
|
content: [{
|
|
1355
1358
|
type: "text",
|
|
1356
1359
|
text: notice
|
|
1357
1360
|
}],
|
|
1358
1361
|
source: { kind: "roleplay" }
|
|
1359
|
-
})
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
+
}));
|
|
1363
|
+
return {
|
|
1364
|
+
kind: "success",
|
|
1365
|
+
text: `Running ${kits.length === 1 ? "the check" : "the checks"}…`
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
})));
|
|
1362
1369
|
}
|
|
1363
1370
|
// src/authoring.ts
|
|
1364
1371
|
const name = "@dsh-agentic-roleplay/core/authoring";
|
|
@@ -1373,6 +1380,7 @@ const inject = [
|
|
|
1373
1380
|
];
|
|
1374
1381
|
function apply(ctx) {
|
|
1375
1382
|
silenceHarnessDevContext(ctx);
|
|
1383
|
+
silenceRuntimeContext(ctx);
|
|
1376
1384
|
const prompting = {
|
|
1377
1385
|
prompts: () => ctx.roleplayPrompts,
|
|
1378
1386
|
languages: () => ctx.roleplayAuthoringLanguages
|
|
@@ -1396,8 +1404,8 @@ function apply(ctx) {
|
|
|
1396
1404
|
settings: () => ctx.roleplayImport.settings,
|
|
1397
1405
|
prompting
|
|
1398
1406
|
})) ctx.tools.register(tool);
|
|
1399
|
-
importHooks(ctx, ctx.roleplayWorlds, prompting);
|
|
1400
|
-
|
|
1407
|
+
importHooks(ctx, ctx.roleplayWorlds, prompting, ctx.roleplayImport.state);
|
|
1408
|
+
checkCommands(ctx, prompting);
|
|
1401
1409
|
updateHooks(ctx, ctx.roleplayWorlds, (world) => ctx.roleplayAuthoringLanguages.get(world));
|
|
1402
1410
|
const reviewing = async (chat) => {
|
|
1403
1411
|
const id = authoredWorldOf(chat);
|
|
@@ -477,8 +477,14 @@ const isUnfinishedCall = (error) => error instanceof Error && /parse tool call a
|
|
|
477
477
|
* lets {@link HelperEntry.setup} give it tools of its own. Several run side by side with different tools and different results from the same tool.
|
|
478
478
|
* @throws {Error} when the child is cancelled, stops without a result, or exceeds its calls.
|
|
479
479
|
*/
|
|
480
|
-
async function runChild(
|
|
481
|
-
|
|
480
|
+
async function runChild(asked) {
|
|
481
|
+
let task = asked;
|
|
482
|
+
let unfinished = 0;
|
|
483
|
+
for (;;) {
|
|
484
|
+
if (task.structured === true && hidesAnswers.has(modelOf(task))) task = {
|
|
485
|
+
...task,
|
|
486
|
+
structured: false
|
|
487
|
+
};
|
|
482
488
|
const began = Date.now();
|
|
483
489
|
const turnAtStart = task.turn ?? currentTurn(task.parent);
|
|
484
490
|
const stats = {
|
|
@@ -522,12 +528,34 @@ async function runChild(task) {
|
|
|
522
528
|
tokens: stats.tokens ?? NO_TOKENS,
|
|
523
529
|
requests: stats.requests ?? []
|
|
524
530
|
});
|
|
525
|
-
if (
|
|
531
|
+
if (task.signal.aborted) throw error;
|
|
532
|
+
if (task.structured === true && error instanceof Error && error.message === "the reply is empty: the answer was written as thinking, which this endpoint does with a constrained reply while the model thinks") {
|
|
533
|
+
const model = modelOf(task);
|
|
534
|
+
if (model !== "") hidesAnswers.add(model);
|
|
535
|
+
task = {
|
|
536
|
+
...task,
|
|
537
|
+
structured: false
|
|
538
|
+
};
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
unfinished += 1;
|
|
542
|
+
if (unfinished >= 2 || error instanceof ChildTimeoutError || !isUnfinishedCall(error)) throw error;
|
|
526
543
|
} finally {
|
|
527
544
|
if (timer !== void 0) clearTimeout(timer);
|
|
528
545
|
}
|
|
529
546
|
}
|
|
530
547
|
}
|
|
548
|
+
/** Models known to return constrained output only in their reasoning block. */
|
|
549
|
+
const hidesAnswers = /* @__PURE__ */ new Set();
|
|
550
|
+
/** The selected model as `provider/model`, or an empty string when it is unknown. */
|
|
551
|
+
function modelOf(task) {
|
|
552
|
+
const config = task.model === void 0 ? task.parent.session.requestHeader?.()?.config : void 0;
|
|
553
|
+
const model = task.model ?? (config?.provider === void 0 || config.model === void 0 ? void 0 : {
|
|
554
|
+
provider: config.provider,
|
|
555
|
+
model: config.model
|
|
556
|
+
});
|
|
557
|
+
return model === void 0 ? "" : `${model.provider}/${model.model}`;
|
|
558
|
+
}
|
|
531
559
|
/**
|
|
532
560
|
* The thinking level a child may be given on its model: the one asked for when the model offers it, none when it does not (a model chosen for a
|
|
533
561
|
* helper has its own levels, and one that lacks the level the chat asks for would refuse the request).
|
|
@@ -575,11 +603,14 @@ function repairedJson(text, accepts = () => true) {
|
|
|
575
603
|
}
|
|
576
604
|
}
|
|
577
605
|
}
|
|
606
|
+
/** A constrained result was returned only as reasoning, leaving the answer empty. */
|
|
607
|
+
const ANSWERED_IN_THINKING = "the reply is empty: the answer was written as thinking, which this endpoint does with a constrained reply while the model thinks";
|
|
578
608
|
/** The result in the last reply of a structured child: its JSON, which must fit the schema; else what is wrong with it. */
|
|
579
609
|
function structuredReply(child, schema, cut = false) {
|
|
580
610
|
const message = child.session.snapshotEvents().findLast((event) => event.type === "assistant/message");
|
|
581
|
-
const
|
|
582
|
-
|
|
611
|
+
const content = message?.type === "assistant/message" ? message.data.message.content : [];
|
|
612
|
+
const text = content.flatMap((block) => block.type === "text" ? [block.text] : []).join("").trim().replace(/^```(?:json)?\s*|\s*```$/g, "");
|
|
613
|
+
if (text === "") return { problem: content.some((block) => block.type === "reasoning" && block.text.trim() !== "") ? ANSWERED_IN_THINKING : "the reply is empty" };
|
|
583
614
|
let value;
|
|
584
615
|
try {
|
|
585
616
|
value = JSON.parse(text);
|
|
@@ -609,6 +640,7 @@ async function execute(task, stats) {
|
|
|
609
640
|
let stepsAfterRetire = -1;
|
|
610
641
|
let overran = false;
|
|
611
642
|
let rambled = false;
|
|
643
|
+
let hidden = false;
|
|
612
644
|
let refusals = 0;
|
|
613
645
|
let lastRefusal = "";
|
|
614
646
|
let previous;
|
|
@@ -785,6 +817,12 @@ async function execute(task, stats) {
|
|
|
785
817
|
outcome: cut(lastRefusal),
|
|
786
818
|
failed: true
|
|
787
819
|
});
|
|
820
|
+
if (lastRefusal === "the reply is empty: the answer was written as thinking, which this endpoint does with a constrained reply while the model thinks") {
|
|
821
|
+
hidden = true;
|
|
822
|
+
overran = true;
|
|
823
|
+
stopped?.();
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
788
826
|
if (refusals >= 5) {
|
|
789
827
|
overran = true;
|
|
790
828
|
stopped?.();
|
|
@@ -910,6 +948,7 @@ async function execute(task, stats) {
|
|
|
910
948
|
}
|
|
911
949
|
if (signal.aborted) throw new Error("cancelled");
|
|
912
950
|
if (rambled && submitted === void 0) throw new Error(`the agent wrote text up to the limit of ${task.maxTokens ?? task.sampling?.maxTokens ?? "its model"} tokens and never called ${SUBMIT_TOOL}, and was stopped`);
|
|
951
|
+
if (hidden && submitted === void 0) throw new Error(ANSWERED_IN_THINKING);
|
|
913
952
|
if (overran && submitted === void 0) throw new Error(refusals >= 5 ? `the result was refused ${refusals} times and the agent was stopped; the last reason: ${lastRefusal}` : `the agent went on past its ${budget} calls, or kept repeating a call that failed, without submitting a result and was stopped`);
|
|
914
953
|
if (submitted === void 0) {
|
|
915
954
|
const ended = entry.agent?.session.snapshotEvents().findLast((event) => event.type === "turn/end");
|
|
@@ -921,4 +960,4 @@ async function execute(task, stats) {
|
|
|
921
960
|
}
|
|
922
961
|
export { chatSessionId as A, addTokens as C, finishOf as D, cutOff as E, estimateAnswer as O, NO_TOKENS as S, currentTurn as T, RECOVERY_SHRINK as _, childTrace as a, estimateTokens as b, namedModel as c, sessionOfChat as d, tracerOf as f, RECOVERY_FLOOR as g, sharedSamplingOf as h, childSamplingOf as i, roleplaySessionOf as j, tokensOf$1 as k, runChild as l, parseSampling as m, childModel as n, helpers as o, SAMPLING_RANGES as p, childSampling as r, isUnfinishedCall as s, ChildTimeoutError as t, TurnTraces as u, requestsOf as v, totalTokens as w, tokensOf as x, blockText as y };
|
|
923
962
|
|
|
924
|
-
//# sourceMappingURL=child-
|
|
963
|
+
//# sourceMappingURL=child-DTdY14S9.js.map
|