pygmalion 0.1.14 → 0.2.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/LICENSE +21 -0
- package/README.md +141 -69
- package/THIRD_PARTY.md +9 -0
- package/docs/ARCHITECTURE.md +66 -107
- package/docs/DEPLOY.md +33 -136
- package/docs/DEVELOPMENT.md +63 -0
- package/docs/DEVICE.md +56 -47
- package/docs/EXTENSIONS.md +176 -0
- package/docs/PRESET.md +21 -63
- package/docs/UPGRADE-0.2.md +52 -0
- package/package.json +52 -33
- package/preset/pygmalion-director/cordis.patch.yml +234 -0
- package/preset/pygmalion-director/pygmalion-tools.js +43 -41
- package/scripts/start-local-test.mjs +45 -45
- package/skills/pygmalion-life-scripts/SKILL.md +12 -0
- package/skills/pygmalion-meme-maintenance/SKILL.md +12 -0
- package/skills/pygmalion-memory-archive/SKILL.md +24 -0
- package/skills/pygmalion-toy-control/SKILL.md +16 -0
- package/src/agent-life.js +608 -606
- package/src/archive-tools.js +9 -0
- package/src/bot-factory.js +129 -306
- package/src/bots.js +264 -275
- package/src/channel-qq.js +262 -0
- package/src/config.js +69 -68
- package/src/delivery-receipt.js +36 -0
- package/src/delivery-scope.js +20 -0
- package/src/devices/manager.mjs +80 -525
- package/src/devices/monsterparty-controller.mjs +393 -0
- package/src/devices/{doc.mjs → monsterparty-doc.mjs} +60 -69
- package/src/devices/monsterparty.mjs +294 -294
- package/src/devices/pb.mjs +110 -110
- package/src/devices/registry.mjs +19 -0
- package/src/devices/script-helper.mjs +45 -0
- package/src/devices/scripts.mjs +109 -0
- package/src/devices/service.mjs +254 -0
- package/src/director-messages.js +35 -0
- package/src/dsh-runtime.js +17 -0
- package/src/extension-config.js +20 -0
- package/src/extensions.js +118 -0
- package/src/heartbeat.js +117 -95
- package/src/http-api.js +519 -509
- package/src/inbound.js +36 -207
- package/src/index.js +109 -37
- package/src/llm-provider.js +214 -171
- package/src/meme-worker.js +35 -39
- package/src/memebox.js +1 -1
- package/src/memory-recall.js +55 -0
- package/src/memory-write.js +136 -133
- package/src/peer-identity.js +26 -0
- package/src/persona.js +120 -41
- package/src/role-agent.js +155 -0
- package/src/role-runtime.js +65 -0
- package/src/roleplay-config.js +37 -0
- package/src/roleplay-format.js +37 -0
- package/src/roleplay-generation.js +36 -0
- package/src/roleplay-materials.js +113 -0
- package/src/roleplay-output.js +19 -0
- package/src/roleplay-parallel.js +239 -0
- package/src/roleplay-session.js +128 -0
- package/src/roleplay-worker.js +10 -0
- package/src/session-log.js +180 -143
- package/src/setup-agent.js +92 -100
- package/src/skills.js +97 -0
- package/src/slash-commands.js +155 -142
- package/src/speech-input.js +20 -0
- package/src/threads.js +2 -1
- package/src/tools.js +216 -168
- package/src/voice-defaults.js +13 -0
- package/src/voice-mimo.js +139 -95
- package/src/voice.js +200 -0
- package/src/wakeup.js +76 -35
- package/src/web-public/app.js +536 -367
- package/src/web-public/index.html +161 -156
- package/src/web-public/layout.css +7 -7
- package/src/web-public/style.css +12 -8
- package/src/web-server.js +158 -89
- package/src/worker-tools.js +18 -0
- package/templates/sample-life.mjs +59 -59
- package/templates/sample-toy.mjs +33 -33
- package/preset/pygmalion-director/agent.cordis.yml +0 -253
- package/preset/pygmalion-director/preset.yml +0 -3
package/src/slash-commands.js
CHANGED
|
@@ -1,142 +1,155 @@
|
|
|
1
|
-
import { targetKey } from './threads.js';
|
|
2
|
-
import { baseSessionId } from './inbound.js';
|
|
3
|
-
export function createSlashHandler(deps) {
|
|
4
|
-
const { log, alwaysAllow, threads, agents, approval, outbound, agentPresets, botId } = deps;
|
|
5
|
-
/** List presets through the host service; `undefined` when unavailable/failed. */
|
|
6
|
-
const listPresets = async () => {
|
|
7
|
-
if (agentPresets === undefined)
|
|
8
|
-
return undefined;
|
|
9
|
-
try {
|
|
10
|
-
return await agentPresets.list();
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
log.warn('QQ slash: listing agent presets failed: %o', error);
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
return async (sessionId, message, text, reply) => {
|
|
18
|
-
if (!text.startsWith('/'))
|
|
19
|
-
return false;
|
|
20
|
-
const [command, ...rest] = text.slice(1).split(/\s+/);
|
|
21
|
-
switch (command) {
|
|
22
|
-
case 'help':
|
|
23
|
-
await reply([
|
|
24
|
-
'/help — 显示可用命令',
|
|
25
|
-
'/ping — 延迟检测',
|
|
26
|
-
'/me — 显示你的 openid',
|
|
27
|
-
'/new [preset] — 开启新会话(可选 preset id,见 /presets)',
|
|
28
|
-
'/
|
|
29
|
-
'/
|
|
30
|
-
'/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
import { targetKey } from './threads.js';
|
|
2
|
+
import { baseSessionId } from './inbound.js';
|
|
3
|
+
export function createSlashHandler(deps) {
|
|
4
|
+
const { log, alwaysAllow, threads, agents, approval, outbound, agentPresets, botId } = deps;
|
|
5
|
+
/** List presets through the host service; `undefined` when unavailable/failed. */
|
|
6
|
+
const listPresets = async () => {
|
|
7
|
+
if (agentPresets === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
try {
|
|
10
|
+
return await agentPresets.list();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
log.warn('QQ slash: listing agent presets failed: %o', error);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return async (sessionId, message, text, reply) => {
|
|
18
|
+
if (!text.startsWith('/'))
|
|
19
|
+
return false;
|
|
20
|
+
const [command, ...rest] = text.slice(1).split(/\s+/);
|
|
21
|
+
switch (command) {
|
|
22
|
+
case 'help':
|
|
23
|
+
await reply([
|
|
24
|
+
'/help — 显示可用命令',
|
|
25
|
+
'/ping — 延迟检测',
|
|
26
|
+
'/me — 显示你的 openid',
|
|
27
|
+
'/new [preset] — 开启新会话(可选 preset id,见 /presets)',
|
|
28
|
+
'/newp — 单独新建角色平行会话,保留当前主会话和记忆',
|
|
29
|
+
'/presets — 列出可用的 agent preset',
|
|
30
|
+
'/approve ask|never|status — 审批策略',
|
|
31
|
+
'/always clear — 清除"始终允许"清单',
|
|
32
|
+
].join('\n'));
|
|
33
|
+
return true;
|
|
34
|
+
case 'ping':
|
|
35
|
+
await reply(`✅ pong(${new Date().toLocaleTimeString()})`);
|
|
36
|
+
return true;
|
|
37
|
+
case 'me':
|
|
38
|
+
await reply(`🆔 你的 openid: \`${message.senderId}\`${message.senderName !== undefined ? `(${message.senderName})` : ''}`);
|
|
39
|
+
return true;
|
|
40
|
+
case 'presets': {
|
|
41
|
+
const presets = await listPresets();
|
|
42
|
+
if (presets === undefined) {
|
|
43
|
+
await reply(agentPresets === undefined
|
|
44
|
+
? '⚠️ 当前环境不支持 preset 查询(host 未加载 agent-presets 服务)'
|
|
45
|
+
: '⚠️ 读取 preset 列表失败,请稍后再试');
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
await reply(presets.length === 0
|
|
49
|
+
? '当前没有可用的 agent preset(检查 host 的 agent-presets 配置)'
|
|
50
|
+
: [
|
|
51
|
+
'可用 agent preset:',
|
|
52
|
+
...presets.map(preset => `- ${preset.id}${preset.name !== undefined ? `(${preset.name})` : ''}${preset.broken !== undefined ? ` ⚠️ 不可用:${preset.broken}` : ''}`),
|
|
53
|
+
'用 /new <id> 以指定 preset 开启新会话',
|
|
54
|
+
].join('\n'));
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
case 'newp': {
|
|
58
|
+
if(rest.some(arg=>arg.length)){await reply('【系统提示】用法:/newp');return true;}
|
|
59
|
+
if(!deps.newParallelSession){await reply('【系统提示】当前环境不支持角色平行会话重置。');return true;}
|
|
60
|
+
try{
|
|
61
|
+
const result=await deps.newParallelSession(message);
|
|
62
|
+
const messages={ready:'已新建角色平行会话。下次生成将重新读取人设、关于TA和近期原文;当前主会话与历史记忆保留。',
|
|
63
|
+
busy:'当前角色回复仍在生成或等待发送。请待本轮回复完成后再发送 /newp,已有回复会继续交付。',
|
|
64
|
+
disabled:'此角色尚未开启独立角色生成模型。',forbidden:'仅角色绑定用户可在私聊中使用 /newp。',unavailable:'角色平行会话服务暂不可用。'};
|
|
65
|
+
await reply('【系统提示】'+(messages[result?.status]??messages.unavailable));
|
|
66
|
+
}catch(error){log.warn('QQ /newp 失败: %o',error);await reply('【系统提示】新建角色平行会话失败,请稍后重试。');}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
case 'new': {
|
|
70
|
+
// Optional argument: the agent preset id the NEW session composes
|
|
71
|
+
// from (validated against the host roster below). Unknown or broken
|
|
72
|
+
// ids are refused BEFORE the thread bumps, so the current thread and
|
|
73
|
+
// its anchor stay untouched.
|
|
74
|
+
const arg = rest[0];
|
|
75
|
+
let presetId;
|
|
76
|
+
if (arg !== undefined) {
|
|
77
|
+
if (agentPresets === undefined) {
|
|
78
|
+
await reply('⚠️ 当前环境不支持按会话指定 preset(host 未加载 agent-presets 服务)');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
const presets = await listPresets();
|
|
82
|
+
if (presets === undefined) {
|
|
83
|
+
await reply('⚠️ 读取 preset 列表失败,请稍后再试');
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
const found = presets.find(preset => preset.id === arg);
|
|
87
|
+
if (found === undefined) {
|
|
88
|
+
const ids = presets.map(preset => preset.id);
|
|
89
|
+
await reply(`⚠️ 未知的 preset “${arg}”。可用:${ids.length > 0 ? ids.join(', ') : '(无)'}。\n用 /presets 查看详情。`);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (found.broken !== undefined) {
|
|
93
|
+
await reply(`⚠️ preset “${arg}” 当前不可用:${found.broken}`);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
presetId = found.id;
|
|
97
|
+
}
|
|
98
|
+
// Cancel any agent still running on the current thread so its queued
|
|
99
|
+
// or mid-stream assistant messages are dropped instead of leaking
|
|
100
|
+
// into the abandoned session id. Force-close the C2C stream first
|
|
101
|
+
// so QQ's "其它流式消息发送中" guard does not block the new thread.
|
|
102
|
+
const key = targetKey(message.reply);
|
|
103
|
+
const before = threads.current(key);
|
|
104
|
+
const oldAgent = agents.get(sessionId);
|
|
105
|
+
await outbound.closeStream(sessionId).catch(() => undefined);
|
|
106
|
+
try {
|
|
107
|
+
oldAgent?.cancel({ kind: 'user' });
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
log.warn('failed to cancel old QQ agent on /new: %o', error);
|
|
111
|
+
}
|
|
112
|
+
const thread = threads.next(key);
|
|
113
|
+
const baseId = baseSessionId(message.reply, botId);
|
|
114
|
+
const newId = thread === 0 ? baseId : `${baseId}#n${thread}`;
|
|
115
|
+
// Record (or explicitly clear) the per-session override so the agent
|
|
116
|
+
// materializing newId composes from it; a plain /new resets to the
|
|
117
|
+
// plugin-config default.
|
|
118
|
+
threads.setPreset(newId, presetId);
|
|
119
|
+
log.info('QQ /new: target=%s beforeThread=%d afterThread=%d oldAgent=%s newSessionId=%s preset=%s', key, before, thread, oldAgent ? 'present' : 'none', newId, presetId ?? '(config default)');
|
|
120
|
+
await reply(presetId === undefined
|
|
121
|
+
? `✅ 已开启新会话(#n${thread})。下次发送的消息将进入 \`${newId}\`。旧的对话仍保留,可手动在侧边栏切换。`
|
|
122
|
+
: `✅ 已开启新会话(#n${thread},preset=${presetId})。下次发送的消息将进入 \`${newId}\`。旧的对话仍保留,可手动在侧边栏切换。`);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
case 'approve': {
|
|
126
|
+
const sub = rest[0] ?? 'status';
|
|
127
|
+
if (sub === 'ask' || sub === 'never') {
|
|
128
|
+
const agent = agents.get(sessionId);
|
|
129
|
+
if (approval === undefined || agent === undefined) {
|
|
130
|
+
await reply('⚠️ 当前环境不支持审批策略切换');
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
approval.setPolicy(agent, sub);
|
|
134
|
+
await reply(`✅ 审批策略已切换为 ${sub}`);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
const listed = alwaysAllow.list(sessionId);
|
|
138
|
+
await reply(listed.length > 0
|
|
139
|
+
? `始终允许的工具:${listed.join(', ')}(用 /approve ask|never 切换策略)`
|
|
140
|
+
: '无始终允许的工具(用 /approve ask|never 切换策略)');
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
case 'always':
|
|
144
|
+
if (rest[0] === 'clear') {
|
|
145
|
+
const removed = alwaysAllow.clear(sessionId);
|
|
146
|
+
await reply(`✅ 已清除 ${removed} 条"始终允许"规则`);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
default:
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=slash-commands.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** 现有 OpenAI 兼容语音转写实现;与通信消息解析分开。 */
|
|
2
|
+
export async function transcribe(stt, wavPath) {
|
|
3
|
+
if (stt.apiKey === undefined || stt.apiKey.length === 0)
|
|
4
|
+
return undefined;
|
|
5
|
+
const { readFile } = await import('node:fs/promises');
|
|
6
|
+
const form = new FormData();
|
|
7
|
+
form.append('file', new Blob([await readFile(wavPath)]), 'audio.wav');
|
|
8
|
+
form.append('model', stt.model);
|
|
9
|
+
const base = stt.baseUrl.replace(/\/+$/, '');
|
|
10
|
+
const response = await fetch(`${base}/audio/transcriptions`, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
headers: { Authorization: `Bearer ${stt.apiKey}` },
|
|
13
|
+
body: form,
|
|
14
|
+
signal: AbortSignal.timeout(60_000),
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok)
|
|
17
|
+
return undefined;
|
|
18
|
+
const data = asRecord(await response.json());
|
|
19
|
+
return typeof data?.text === 'string' ? data.text : undefined;
|
|
20
|
+
}
|
package/src/threads.js
CHANGED
|
@@ -65,6 +65,7 @@ async function writeJsonAtomic(file, value) {
|
|
|
65
65
|
}
|
|
66
66
|
/** Stable target key: c2c:openid | group:openid | channel:channel_id. */
|
|
67
67
|
export function targetKey(target) {
|
|
68
|
+
if (target.kind === 'direct') return `direct:${JSON.stringify(target.identity)}`;
|
|
68
69
|
if (target.kind === 'c2c')
|
|
69
70
|
return `c2c:${target.userId}`;
|
|
70
71
|
if (target.kind === 'group')
|
|
@@ -115,4 +116,4 @@ export class ThreadStore {
|
|
|
115
116
|
this.writing = this.writing.then(() => writeJsonAtomic(this.file, this.payload), () => writeJsonAtomic(this.file, this.payload));
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
//# sourceMappingURL=threadstore.js.map
|
|
119
|
+
//# sourceMappingURL=threadstore.js.map
|