@dsh-agentic-roleplay/core 0.3.1 → 0.3.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.
Files changed (39) hide show
  1. package/lib/authoring.js +13 -2
  2. package/lib/child-lPncV1ps.js +380 -0
  3. package/lib/client.js +1526 -356
  4. package/lib/client.js.map +1 -1
  5. package/lib/compaction.js +1 -1
  6. package/lib/deliver-De62a8i9.js +1929 -0
  7. package/lib/doctor-chat-ByDfCMeo.js +17 -0
  8. package/lib/doctor.js +95 -0
  9. package/lib/{documents-DtlY2IRt.js → documents-Do4lz4SB.js} +549 -64
  10. package/lib/{gallery-DACG5eh2.js → gallery-CtFDL22W.js} +2 -2
  11. package/lib/{generator-DGYcLMp7.js → generator-B6FxlKOV.js} +2 -378
  12. package/lib/hooks-Ka22sFNy.js +1019 -0
  13. package/lib/images.js +3 -3
  14. package/lib/index.js +303 -190
  15. package/lib/language-DWVwi1R7.js +520 -0
  16. package/lib/narration-DK2kiIjE.js +141 -0
  17. package/lib/orchestration.js +777 -2542
  18. package/lib/{packs-CkRZDCsV.js → packs-BYjrAen6.js} +4 -518
  19. package/lib/{presenter-agent-PK9JYExk.js → presenter-agent-Dt21K96b.js} +4 -3
  20. package/lib/{deliver-BDW5WZvc.js → reflection-md7BCYCl.js} +350 -769
  21. package/lib/{narration-5ig7Dg28.js → settings-CA6icLL_.js} +156 -141
  22. package/package.json +3 -2
  23. package/prompts/en/doctor/persona.md +1 -0
  24. package/prompts/en/doctor/procedure.md +5 -0
  25. package/prompts/en/doctor/welcome.md +1 -0
  26. package/prompts/en/import/character.md +1 -0
  27. package/prompts/en/roleplay/dice.md +7 -0
  28. package/prompts/en/roleplay/game-master.md +2 -0
  29. package/prompts/en/roleplay/reflection-check.md +5 -0
  30. package/prompts/en/roleplay/reflection.md +5 -1
  31. package/prompts/zh/doctor/persona.md +1 -0
  32. package/prompts/zh/doctor/procedure.md +5 -0
  33. package/prompts/zh/doctor/welcome.md +1 -0
  34. package/prompts/zh/import/character.md +1 -0
  35. package/prompts/zh/roleplay/dice.md +7 -0
  36. package/prompts/zh/roleplay/game-master.md +2 -0
  37. package/prompts/zh/roleplay/reflection-check.md +5 -0
  38. package/prompts/zh/roleplay/reflection.md +5 -1
  39. package/lib/src-CWTNeL6Y.js +0 -128
@@ -0,0 +1,17 @@
1
+ //#region src/shared/doctor-chat.ts
2
+ const PREFIX = "doctor-";
3
+ const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
4
+ /** Stable DSH chat identity for the session doctor of one roleplay session. */
5
+ function doctorChatSessionId(sessionId) {
6
+ return `${PREFIX}${sessionId}`;
7
+ }
8
+ /** The roleplay session a session doctor chat looks after. */
9
+ function doctorSessionOf(chat) {
10
+ if (!chat.startsWith(PREFIX)) return void 0;
11
+ const id = chat.slice(7);
12
+ return UUID_V4.test(id) ? id : void 0;
13
+ }
14
+ //#endregion
15
+ export { doctorSessionOf as n, doctorChatSessionId as t };
16
+
17
+ //# sourceMappingURL=doctor-chat-ByDfCMeo.js.map
package/lib/doctor.js ADDED
@@ -0,0 +1,95 @@
1
+ import "./language-DWVwi1R7.js";
2
+ import { l as externalTools } from "./deliver-De62a8i9.js";
3
+ import { a as liveSettings } from "./narration-DK2kiIjE.js";
4
+ import { n as doctorSessionOf } from "./doctor-chat-ByDfCMeo.js";
5
+ import { t as externalToolLimit } from "./hooks-Ka22sFNy.js";
6
+ import { join } from "node:path";
7
+ import { existsSync } from "node:fs";
8
+ import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
9
+ //#region src/doctor.ts
10
+ const name = "@dsh-agentic-roleplay/core/doctor";
11
+ const inject = [
12
+ "roleplayState",
13
+ "roleplayRoot",
14
+ "roleplayPrompts",
15
+ "tools",
16
+ "systemPrompt"
17
+ ];
18
+ const DOCTOR_TOOL = "edit_records";
19
+ const SHOWN_EDIT = 700;
20
+ /** What the person is asked to approve: the edit, as it will be applied. */
21
+ function doctorApproval(exec) {
22
+ if (exec.name !== DOCTOR_TOOL || exec.agent === void 0 || doctorSessionOf(exec.agent.session.id) === void 0) return void 0;
23
+ const { turn: _turn, ...edit } = exec.arguments;
24
+ if (Object.keys(edit).length === 0) return {
25
+ kind: "deny",
26
+ reason: "the edit changes nothing: put what to change in it (for example states, beliefs, relationships, item_changes)"
27
+ };
28
+ const text = JSON.stringify(edit);
29
+ const shown = text.length > SHOWN_EDIT ? `${text.slice(0, SHOWN_EDIT)}…` : text;
30
+ return {
31
+ kind: "ask",
32
+ reason: `change the story's records: ${shown}`,
33
+ displayReason: {
34
+ en: `Change the story's records?\n${shown}`,
35
+ zh: `修改故事的记录?\n${shown}`
36
+ }
37
+ };
38
+ }
39
+ function apply(ctx) {
40
+ const sessionsDir = () => join(ctx.roleplayRoot.path, "sessions");
41
+ const resolve = (chat) => {
42
+ const id = doctorSessionOf(chat);
43
+ if (id === void 0 || !isSessionId(id) || !existsSync(sessionDatabase(sessionsDir(), id))) return void 0;
44
+ const session = ctx.roleplayState.openSession(sessionsDir(), id);
45
+ const settings = liveSettings(sessionFolder(sessionsDir(), id));
46
+ return {
47
+ session,
48
+ turn: session.metadata.get().turns,
49
+ policy: settings.memory,
50
+ timeZone: settings.clock.timeZone
51
+ };
52
+ };
53
+ ctx.effect(() => ctx.roleplayState.bind(resolve), "roleplay: session doctor reads");
54
+ for (const tool of createTools(resolve, { write: true }).filter((candidate) => candidate.name === DOCTOR_TOOL)) ctx.tools.register(inTurn(tool, resolve));
55
+ ctx.on("tools/pre-execute", async (exec, next) => doctorApproval(exec) ?? await next());
56
+ ctx.on("agent/created", ({ agent }) => {
57
+ if (doctorSessionOf(agent.session.id) !== void 0 && agent.session.header.origin !== "subagent") externalToolLimit(agent, externalTools(agent.ctx.tools).map((tool) => tool.name));
58
+ });
59
+ const languageOf = (context) => {
60
+ const chat = context.agent?.session.id;
61
+ const id = chat === void 0 ? void 0 : doctorSessionOf(chat);
62
+ return id !== void 0 && isSessionId(id) && existsSync(sessionDatabase(sessionsDir(), id)) ? liveSettings(sessionFolder(sessionsDir(), id)).prompts.language : "en";
63
+ };
64
+ for (const [section, order, id] of [[
65
+ "SESSION_DOCTOR_PERSONA",
66
+ ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
67
+ "doctor/persona"
68
+ ], [
69
+ "SESSION_DOCTOR_PROCEDURE",
70
+ ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_SUFFIX"),
71
+ "doctor/procedure"
72
+ ]]) ctx.systemPrompt.section({
73
+ name: section,
74
+ order,
75
+ interpolate: false,
76
+ text: (context) => ctx.roleplayPrompts.text(id, languageOf(context))
77
+ });
78
+ }
79
+ /** The edit is written at the turn the story is at (the first, in a story with none played), whatever turn the model put in it. */
80
+ function inTurn(tool, resolve) {
81
+ return {
82
+ ...tool,
83
+ async execute(args, exec) {
84
+ const link = exec.agent === void 0 ? void 0 : resolve(exec.agent.session.id);
85
+ return await tool.execute(link === void 0 ? args : {
86
+ ...args,
87
+ turn: Math.max(1, link.turn)
88
+ }, exec);
89
+ }
90
+ };
91
+ }
92
+ //#endregion
93
+ export { apply, doctorApproval, inject, name };
94
+
95
+ //# sourceMappingURL=doctor.js.map