@dsh-agentic-roleplay/core 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/{access-CfQWbNZP.js → access-CXtaZNbx.js} +50 -2
- package/lib/{authoring-tools-C_l07RYn.js → authoring-tools-C6Hzy8jU.js} +1571 -1301
- package/lib/authoring.js +19 -8
- package/lib/{child-lYYeOwl2.js → child-C8r8AFpm.js} +150 -14
- package/lib/client.js +6295 -3329
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/doctor.js +3 -3
- package/lib/{gallery-q7niLtWn.js → gallery-CtG-bDzz.js} +5 -9
- package/lib/{generator-BpjPrvHe.js → generator-nLoPM5MF.js} +2 -2
- package/lib/helper.js +1 -1
- package/lib/{hooks-DNaDzMjW.js → hooks-BuQ61nvQ.js} +207 -56
- package/lib/images.js +4 -4
- package/lib/index.js +1312 -125
- package/lib/{library-CIkxhf_R.js → library-CH-ahlm0.js} +7 -14
- package/lib/{lorebook-author-tools-BiMDmdFi.js → lorebook-author-tools-B6_Jj8oe.js} +7 -7
- package/lib/lorebook-authoring.js +4 -4
- package/lib/{narration-CjB_KwwY.js → narration-B0hConSw.js} +11 -53
- package/lib/orchestration.js +196 -14
- package/lib/{pack-jail-B35Vx3hT.js → pack-jail-OZSgU85i.js} +11 -11
- package/lib/{packs-BajKw7S9.js → packs-B88bxt8E.js} +2 -2
- package/lib/{presenter-agent-jgtuTwZr.js → presenter-agent-D-WNs626.js} +12 -17
- package/lib/{preset-DWgkcPau.js → preset-DNuqvMan.js} +4 -4
- package/lib/{preset-author-tools-BhuYIKms.js → preset-author-tools-CDwavcTb.js} +7 -7
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-9GzaSELc.js → presets-9_MNxwaw.js} +105 -10
- package/lib/{reflection-4L0Plvct.js → reflection-BvM0w1R4.js} +179 -112
- package/lib/{text-CbGQhK1-.js → text-CzqhC8sT.js} +11 -1
- package/lib/{turn-guard-sCUXmp-5.js → turn-guard-Ygdww1Wt.js} +3 -3
- package/package.json +2 -2
- package/prompts/en/checks/conflict.md +1 -1
- package/prompts/en/checks/decide-conflict.md +1 -1
- package/prompts/en/checks/decide-opening.md +1 -1
- package/prompts/en/checks/decide-same-value.md +1 -1
- package/prompts/en/checks/decide-sheet.md +1 -1
- package/prompts/en/checks/decide-stated.md +1 -0
- package/prompts/en/checks/fidelity.md +1 -0
- package/prompts/zh/checks/conflict.md +1 -1
- package/prompts/zh/checks/decide-conflict.md +1 -1
- package/prompts/zh/checks/decide-opening.md +1 -1
- package/prompts/zh/checks/decide-same-value.md +1 -1
- package/prompts/zh/checks/decide-sheet.md +1 -1
- package/prompts/zh/checks/decide-stated.md +1 -0
- package/prompts/zh/checks/fidelity.md +1 -0
package/lib/authoring.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { t as guardAuthoringTurns } from "./turn-guard-
|
|
3
|
-
import { C as readWorldEditor, L as presetTools, M as deleteTriggerDocument, N as readTriggerDocuments, P as writeTriggerDocument, U as finishUpdate, W as pendingUpdate, _ as editWorldPlots, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, i as checkWorldPack, l as deleteAuthoredEntity, o as listWorldPacks, r as registerPackJail, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument, v as editWorldRelation, z as translateTools } from "./pack-jail-
|
|
4
|
-
import {
|
|
5
|
-
import { i as translator, r as languageOf } from "./text-
|
|
6
|
-
import {
|
|
7
|
-
import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-
|
|
8
|
-
import "./access-
|
|
1
|
+
import { $ as readSource, A as editsSince, C as worldFieldChanges, D as loadCardEvidence, E as loadWorldParts, J as UPDATE_FOLDER, O as CHECK_COMMANDS, Q as entitiesByPiece, S as pictureChange, T as readWorldInfo, Z as cardTools, _ as runChecks, a as importHooks, b as diffText, g as CHECKS, gt as checkWorld, h as presentReport, i as contextOf, l as isReviewing, m as checkImported, n as limitAuthoringAgents, nt as parseWorldInfoEdit, o as importTools, on as authoredWorldOf, v as addressChanges, w as editWorldInfo, x as matchPieces, y as cardChanges } from "./authoring-tools-C6Hzy8jU.js";
|
|
2
|
+
import { t as guardAuthoringTurns } from "./turn-guard-Ygdww1Wt.js";
|
|
3
|
+
import { C as readWorldEditor, L as presetTools, M as deleteTriggerDocument, N as readTriggerDocuments, P as writeTriggerDocument, U as finishUpdate, W as pendingUpdate, _ as editWorldPlots, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, i as checkWorldPack, l as deleteAuthoredEntity, o as listWorldPacks, r as registerPackJail, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument, v as editWorldRelation, z as translateTools } from "./pack-jail-OZSgU85i.js";
|
|
4
|
+
import { $ as IMPORT_FOLDER, At as InvalidEditProblems, Ft as parseRelationEdit, G as deleteWorldPrompt, J as writeWorldPrompt, K as listWorldPrompts, W as PROSE_PROMPTS, dt as parseAuthoringCommand, nt as PICTURE_FILE, q as readWorldPrompt } from "./presets-9_MNxwaw.js";
|
|
5
|
+
import { i as translator, r as languageOf } from "./text-CzqhC8sT.js";
|
|
6
|
+
import { H as parsePlotsFile, Y as formatIssue, ot as shippedPromptsDirectory } from "./hooks-BuQ61nvQ.js";
|
|
7
|
+
import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-B88bxt8E.js";
|
|
8
|
+
import "./access-CXtaZNbx.js";
|
|
9
9
|
import { join, relative } from "node:path";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
10
11
|
import { readFile, readdir } from "node:fs/promises";
|
|
11
12
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
12
13
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
@@ -921,6 +922,10 @@ async function loreTitles(directory) {
|
|
|
921
922
|
}
|
|
922
923
|
return titles;
|
|
923
924
|
}
|
|
925
|
+
const hashOf = async (file) => await readFile(file).then((bytes) => createHash("sha256").update(bytes).digest("hex"), (error) => {
|
|
926
|
+
if (error.code === "ENOENT") return void 0;
|
|
927
|
+
throw error;
|
|
928
|
+
});
|
|
924
929
|
const output$1 = {
|
|
925
930
|
schema: { type: "json" },
|
|
926
931
|
render: (_args, value) => [{
|
|
@@ -985,8 +990,14 @@ function updateTools(worlds) {
|
|
|
985
990
|
}];
|
|
986
991
|
});
|
|
987
992
|
const edits = await editsSince(directory);
|
|
993
|
+
const picture = pictureChange(await hashOf(join(directory, IMPORT_FOLDER, PICTURE_FILE)), await hashOf(join(directory, IMPORT_FOLDER, UPDATE_FOLDER, PICTURE_FILE)));
|
|
988
994
|
return json({
|
|
989
995
|
card: cardChanges(before.card, after.card),
|
|
996
|
+
images: {
|
|
997
|
+
cardPicture: picture,
|
|
998
|
+
...addressChanges(before.card, after.card),
|
|
999
|
+
effect: "A changed card picture replaces the portrait that is still the card's picture when the update is finished; a portrait the person changed is kept. Pictures the card no longer points to stay in the image library."
|
|
1000
|
+
},
|
|
990
1001
|
changed: changed.slice(0, MAX_PIECES),
|
|
991
1002
|
...changed.length > MAX_PIECES ? { moreChanged: changed.length - MAX_PIECES } : {},
|
|
992
1003
|
added: match.added.slice(0, MAX_PIECES).map((piece) => ({
|
|
@@ -43,11 +43,16 @@ const NO_TOKENS = {
|
|
|
43
43
|
cached: 0,
|
|
44
44
|
output: 0
|
|
45
45
|
};
|
|
46
|
-
const addTokens = (a, b) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const addTokens = (a, b) => {
|
|
47
|
+
const unreported = (a.unreported ?? 0) + (b.unreported ?? 0);
|
|
48
|
+
return {
|
|
49
|
+
input: a.input + b.input,
|
|
50
|
+
cached: a.cached + b.cached,
|
|
51
|
+
output: a.output + b.output,
|
|
52
|
+
...unreported > 0 ? { unreported } : {}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const totalTokens = (count) => count.input + count.cached + count.output;
|
|
51
56
|
// src/host/agents/usage.ts
|
|
52
57
|
/** The tokens the model service reported for the requests it answered in a session's events; a request it reported nothing for adds nothing. */
|
|
53
58
|
function tokensOf(events) {
|
|
@@ -59,11 +64,127 @@ function tokensOf(events) {
|
|
|
59
64
|
total = addTokens(total, {
|
|
60
65
|
input: usage.inputTokens,
|
|
61
66
|
cached: usage.cacheReadTokens ?? 0,
|
|
62
|
-
output: usage.outputTokens
|
|
67
|
+
output: usage.outputTokens,
|
|
68
|
+
...usage.cacheReadTokens === void 0 ? { unreported: usage.inputTokens } : {}
|
|
63
69
|
});
|
|
64
70
|
}
|
|
65
71
|
return total;
|
|
66
72
|
}
|
|
73
|
+
// src/host/diagnostics/estimate.ts
|
|
74
|
+
const WIDE = /[ -鿿가--]/gu;
|
|
75
|
+
/** What a text costs in tokens, roughly: a token holds about four letters of a western script and less than one character of a Chinese, Japanese or Korean one. Only for telling the parts of a prompt apart; the service's own count is what is reported for the whole. */
|
|
76
|
+
function estimateTokens(text) {
|
|
77
|
+
if (text === "") return 0;
|
|
78
|
+
const wide = text.match(WIDE)?.length ?? 0;
|
|
79
|
+
return Math.ceil((text.length - wide) / 4 + wide * .7);
|
|
80
|
+
}
|
|
81
|
+
/** The text a block of a model message puts in the prompt. */
|
|
82
|
+
function blockText(block) {
|
|
83
|
+
if (typeof block !== "object" || block === null) return "";
|
|
84
|
+
const entry = block;
|
|
85
|
+
if (typeof entry.text === "string") return entry.text;
|
|
86
|
+
if (entry.type === "tool-call") return `${typeof entry.name === "string" ? entry.name : ""}${typeof entry.arguments === "string" ? entry.arguments : JSON.stringify(entry.arguments ?? "")}`;
|
|
87
|
+
if (entry.type === "image") return "";
|
|
88
|
+
return JSON.stringify(block);
|
|
89
|
+
}
|
|
90
|
+
/** The tokens of the content of one message of the log. */
|
|
91
|
+
function messageTokens(message) {
|
|
92
|
+
const content = message?.content;
|
|
93
|
+
if (typeof content === "string") return estimateTokens(content);
|
|
94
|
+
return Array.isArray(content) ? content.reduce((sum, block) => sum + estimateTokens(blockText(block)), 0) : 0;
|
|
95
|
+
}
|
|
96
|
+
const MAX_SECTIONS = 24;
|
|
97
|
+
const MAX_TITLE = 80;
|
|
98
|
+
const HEADING = /^(.{1,200}?)[::]\s*$/u;
|
|
99
|
+
/**
|
|
100
|
+
* The parts of a helper's brief, as the brief itself divides them: it is written in paragraphs, and a paragraph whose first line ends in a colon opens a new part with that line as its
|
|
101
|
+
* title. Text before the first heading is the part called with an empty title. Sizes are estimated.
|
|
102
|
+
*/
|
|
103
|
+
function briefSections(prompt) {
|
|
104
|
+
const parts = [];
|
|
105
|
+
for (const block of prompt.split(/\n{2,}/)) {
|
|
106
|
+
if (block.trim() === "") continue;
|
|
107
|
+
const heading = HEADING.exec(block.split("\n")[0]);
|
|
108
|
+
if (heading !== null || parts.length === 0) parts.push({
|
|
109
|
+
title: heading === null ? "" : heading[1].trim().slice(0, MAX_TITLE),
|
|
110
|
+
text: [block]
|
|
111
|
+
});
|
|
112
|
+
else parts[parts.length - 1].text.push(block);
|
|
113
|
+
}
|
|
114
|
+
return parts.slice(0, MAX_SECTIONS).map((part) => ({
|
|
115
|
+
title: part.title,
|
|
116
|
+
tokens: estimateTokens(part.text.join("\n\n"))
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
// src/host/agents/requests.ts
|
|
120
|
+
/** What a request's prompt was made of: the parts the log shows, and whatever else the service counted (the earlier turns of the conversation). */
|
|
121
|
+
function parts(held, prompt) {
|
|
122
|
+
const known = Object.keys(held).filter((id) => held[id] > 0).map((id) => ({
|
|
123
|
+
id,
|
|
124
|
+
tokens: held[id]
|
|
125
|
+
}));
|
|
126
|
+
const rest = prompt === void 0 ? 0 : prompt - known.reduce((sum, part) => sum + part.tokens, 0);
|
|
127
|
+
const all = rest > 0 ? [...known, {
|
|
128
|
+
id: "earlier",
|
|
129
|
+
tokens: rest
|
|
130
|
+
}] : known;
|
|
131
|
+
return all.length === 0 ? {} : { parts: all };
|
|
132
|
+
}
|
|
133
|
+
const KEEP_WAITING = /* @__PURE__ */ new Set([
|
|
134
|
+
"block-start",
|
|
135
|
+
"text-delta",
|
|
136
|
+
"reasoning-delta"
|
|
137
|
+
]);
|
|
138
|
+
/**
|
|
139
|
+
* The requests a session's events record, in order. The wait is measured from the start of the step to the first block the model opened;
|
|
140
|
+
* whatever DSH took to assemble the request is in it, which is small beside a model's own time to read the prompt.
|
|
141
|
+
*/
|
|
142
|
+
function requestsOf(events) {
|
|
143
|
+
const stats = [];
|
|
144
|
+
const began = /* @__PURE__ */ new Map();
|
|
145
|
+
const held = {
|
|
146
|
+
system: 0,
|
|
147
|
+
tools: 0,
|
|
148
|
+
notices: 0,
|
|
149
|
+
input: 0,
|
|
150
|
+
steps: 0
|
|
151
|
+
};
|
|
152
|
+
for (const event of events) {
|
|
153
|
+
const data = event.data;
|
|
154
|
+
const key = `${data?.turn ?? 0}:${data?.step ?? 0}`;
|
|
155
|
+
if (event.type === "step/start" && event.time !== void 0) began.set(key, event.time);
|
|
156
|
+
if (event.type === "turn/start") held.notices = held.input = held.steps = 0;
|
|
157
|
+
if (event.type === "system/message") held.system = messageTokens(data?.message);
|
|
158
|
+
if (event.type === "request/header") held.tools = estimateTokens(JSON.stringify(data?.header?.tools ?? []));
|
|
159
|
+
if (event.type === "user/message") held[data?.source?.kind === "roleplay" ? "notices" : "input"] += messageTokens(data);
|
|
160
|
+
if (event.type === "tool/result") held.steps += messageTokens(data?.message);
|
|
161
|
+
if (event.type !== "assistant/message") continue;
|
|
162
|
+
const sent = { ...held };
|
|
163
|
+
if (data?.message !== void 0) held.steps += messageTokens(data.message);
|
|
164
|
+
if (data?.stream === void 0 || stats.length >= 40) continue;
|
|
165
|
+
const start = began.get(key);
|
|
166
|
+
const chunks = data.stream.flatMap((entry) => entry.chunk === void 0 ? [] : [{
|
|
167
|
+
time: entry.time,
|
|
168
|
+
chunk: entry.chunk
|
|
169
|
+
}]);
|
|
170
|
+
const usage = chunks.findLast((entry) => entry.chunk.type === "usage")?.chunk.usage ?? data.usage;
|
|
171
|
+
const first = chunks.find((entry) => KEEP_WAITING.has(entry.chunk.type))?.time;
|
|
172
|
+
const stop = chunks.findLast((entry) => entry.chunk.type === "finish")?.chunk.reason?.kind ?? "stop";
|
|
173
|
+
const cached = usage?.cacheReadTokens;
|
|
174
|
+
const prompt = usage?.inputTokens === void 0 ? void 0 : usage.inputTokens + (cached ?? 0) + (usage.cacheWriteTokens ?? 0);
|
|
175
|
+
stats.push({
|
|
176
|
+
step: data.step ?? 0,
|
|
177
|
+
...prompt === void 0 ? {} : { prompt },
|
|
178
|
+
...usage?.outputTokens === void 0 ? {} : { output: usage.outputTokens },
|
|
179
|
+
...cached === void 0 ? {} : { cached },
|
|
180
|
+
...start === void 0 || first === void 0 ? {} : { waitMs: Math.max(0, first - start) },
|
|
181
|
+
...start === void 0 || event.time === void 0 ? {} : { ms: Math.max(0, event.time - start) },
|
|
182
|
+
stop,
|
|
183
|
+
...parts(sent, prompt)
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return stats;
|
|
187
|
+
}
|
|
67
188
|
// src/shared/activity.ts
|
|
68
189
|
/** Longest text kept for one call's arguments or outcome, and for the persona, the prompt and the result. */
|
|
69
190
|
const MAX_RUN_TEXT = 4e3;
|
|
@@ -175,8 +296,12 @@ function childSampling(settings, kind, estimate) {
|
|
|
175
296
|
priority: kind === "characters" || kind === "authoring" ? "foreground" : "background"
|
|
176
297
|
};
|
|
177
298
|
}
|
|
299
|
+
const briefOf = (prompt) => {
|
|
300
|
+
const brief = briefSections(prompt);
|
|
301
|
+
return brief.length > 1 ? { brief } : {};
|
|
302
|
+
};
|
|
178
303
|
/** What a caller passes as `trace`: files each run of a kind of helper under a label in the store's record of activity, with its detail when the chat keeps it. */
|
|
179
|
-
function childTrace(store, kind, label, extra = {}, named) {
|
|
304
|
+
function childTrace(store, kind, label, extra = {}, named, cause) {
|
|
180
305
|
const model = (named ?? store.settings().models[kind]).trim();
|
|
181
306
|
return (run) => {
|
|
182
307
|
const keep = store.settings().diagnostics.keepRuns;
|
|
@@ -187,8 +312,12 @@ function childTrace(store, kind, label, extra = {}, named) {
|
|
|
187
312
|
model,
|
|
188
313
|
ms: run.ms,
|
|
189
314
|
calls: run.calls,
|
|
315
|
+
...cause === void 0 ? {} : { cause },
|
|
316
|
+
...briefOf(run.detail.prompt),
|
|
317
|
+
...run.detail.calls.some((call) => call.failed) ? { refused: run.detail.calls.filter((call) => call.failed).length } : {},
|
|
190
318
|
turn: run.turn,
|
|
191
319
|
tokens: run.tokens,
|
|
320
|
+
...(run.requests ?? []).length === 0 ? {} : { requests: run.requests },
|
|
192
321
|
...run.error === void 0 ? {} : { error: run.error.slice(0, 300) },
|
|
193
322
|
...id === void 0 ? {} : { run: id }
|
|
194
323
|
}, keep ? {
|
|
@@ -247,6 +376,7 @@ const isUnfinishedCall = (error) => error instanceof Error && /parse tool call a
|
|
|
247
376
|
async function runChild(task) {
|
|
248
377
|
for (let attempt = 1;; attempt += 1) {
|
|
249
378
|
const began = Date.now();
|
|
379
|
+
const turnAtStart = currentTurn(task.parent);
|
|
250
380
|
const stats = {
|
|
251
381
|
calls: 0,
|
|
252
382
|
record: []
|
|
@@ -272,8 +402,9 @@ async function runChild(task) {
|
|
|
272
402
|
ms: Date.now() - began,
|
|
273
403
|
calls: stats.calls,
|
|
274
404
|
detail: detail(),
|
|
275
|
-
turn:
|
|
276
|
-
tokens: stats.tokens ?? NO_TOKENS
|
|
405
|
+
turn: turnAtStart,
|
|
406
|
+
tokens: stats.tokens ?? NO_TOKENS,
|
|
407
|
+
requests: stats.requests ?? []
|
|
277
408
|
});
|
|
278
409
|
return result;
|
|
279
410
|
} catch (cause) {
|
|
@@ -283,8 +414,9 @@ async function runChild(task) {
|
|
|
283
414
|
calls: stats.calls,
|
|
284
415
|
error: error instanceof Error ? error.message : String(error),
|
|
285
416
|
detail: detail(),
|
|
286
|
-
turn:
|
|
287
|
-
tokens: stats.tokens ?? NO_TOKENS
|
|
417
|
+
turn: turnAtStart,
|
|
418
|
+
tokens: stats.tokens ?? NO_TOKENS,
|
|
419
|
+
requests: stats.requests ?? []
|
|
288
420
|
});
|
|
289
421
|
if (attempt >= 2 || task.signal.aborted || error instanceof ChildTimeoutError || !isUnfinishedCall(error)) throw error;
|
|
290
422
|
} finally {
|
|
@@ -631,7 +763,11 @@ async function execute(task, stats) {
|
|
|
631
763
|
} catch (error) {
|
|
632
764
|
if (submitted === void 0 && !overran && !signal.aborted) throw error;
|
|
633
765
|
} finally {
|
|
634
|
-
if (entry.agent !== void 0)
|
|
766
|
+
if (entry.agent !== void 0) {
|
|
767
|
+
const events = entry.agent.session.snapshotEvents();
|
|
768
|
+
stats.tokens = tokensOf(events);
|
|
769
|
+
stats.requests = requestsOf(events);
|
|
770
|
+
}
|
|
635
771
|
await (overran ? Promise.race([activation.dispose(), new Promise((resolve) => {
|
|
636
772
|
setTimeout(resolve, STOP_GRACE_MS);
|
|
637
773
|
})]) : activation.dispose());
|
|
@@ -651,6 +787,6 @@ async function execute(task, stats) {
|
|
|
651
787
|
}
|
|
652
788
|
return submitted.value;
|
|
653
789
|
}
|
|
654
|
-
export {
|
|
790
|
+
export { tokensOf$1 as C, estimateAnswer as S, addTokens as _, childTrace as a, cutOff as b, runChild as c, sharedSamplingOf as d, requestsOf as f, NO_TOKENS as g, tokensOf as h, childSamplingOf as i, SAMPLING_RANGES as l, estimateTokens as m, childModel as n, helpers as o, blockText as p, childSampling as r, namedModel as s, ChildTimeoutError as t, parseSampling as u, totalTokens as v, finishOf as x, currentTurn as y };
|
|
655
791
|
|
|
656
|
-
//# sourceMappingURL=child-
|
|
792
|
+
//# sourceMappingURL=child-C8r8AFpm.js.map
|