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/web-server.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* GET /api/me/roles/<roleId> → 完整角色(persona/model/proactive/binding/bot/脚本状态)
|
|
21
21
|
* PUT /api/me/roles/<roleId> { persona?, model?, proactive? }
|
|
22
22
|
* DELETE /api/me/roles/<roleId> → 级联删除该角色的机器人
|
|
23
|
-
* PUT /api/me/roles/<roleId>/bot { qqAppId, qqSecret?, sandbox?, withinChatWindowMs?, streaming?, enabled? }
|
|
23
|
+
* PUT /api/me/roles/<roleId>/bot { qqAppId, qqSecret?, sandbox?, withinChatWindowMs?, streaming?, enabled? }
|
|
24
24
|
* DELETE /api/me/roles/<roleId>/bot
|
|
25
25
|
* POST /api/me/roles/<roleId>/reset-binding
|
|
26
26
|
* GET /api/me/roles/<roleId>/life → 脚本监管:manifest + logs + backups + running 清单
|
|
@@ -29,20 +29,21 @@
|
|
|
29
29
|
* POST /api/me/roles/<roleId>/life/stop → 终止一个运行中脚本(body: { runId })
|
|
30
30
|
*/
|
|
31
31
|
import { createServer } from 'node:http';
|
|
32
|
-
import { readFile, readdir } from 'node:fs/promises';
|
|
32
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
33
33
|
import { existsSync } from 'node:fs';
|
|
34
34
|
import { join, extname } from 'node:path';
|
|
35
35
|
import { fileURLToPath } from 'node:url';
|
|
36
36
|
import path from 'node:path';
|
|
37
|
-
import { listLifeScripts, listRunningLifeScripts, stopLifeScript, stopLifeScripts, recoverLifeScripts
|
|
38
|
-
import { roleUsesCustomProvider, roleUsesCustomSubagentApi } from './llm-provider.js';
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
37
|
+
import { listLifeScripts, listRunningLifeScripts, stopLifeScript, stopLifeScripts, recoverLifeScripts } from './agent-life.js';
|
|
38
|
+
import { roleUsesCustomProvider, roleUsesCustomSubagentApi, roleUsesCustomRoleplayApi } from './llm-provider.js';
|
|
39
|
+
import { normalizeRoleplayConfig, publicRoleplayConfig, validateEnabledRoleplay, RoleplayConfigError, roleplayConfigSignature } from './roleplay-config.js';
|
|
40
|
+
import { listMemes, saveMeme, updateMeme, deleteMeme, memeFileFor } from './memebox.js';
|
|
41
|
+
import { createBundledVoiceServices } from './voice-defaults.js';
|
|
41
42
|
|
|
42
43
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
43
44
|
const PUBLIC_DIR = join(__dirname, 'web-public');
|
|
44
45
|
const COOKIE_NAME = 'pygmalion_sid';
|
|
45
|
-
const BODY_LIMIT = 12 * 1024 * 1024;
|
|
46
|
+
const BODY_LIMIT = 12 * 1024 * 1024;
|
|
46
47
|
const LOGIN_MAX_FAILS = 5;
|
|
47
48
|
const LOGIN_LOCK_MS = 15 * 60 * 1000;
|
|
48
49
|
const MIME = {
|
|
@@ -53,6 +54,9 @@ const MIME = {
|
|
|
53
54
|
|
|
54
55
|
export function createWebServer(deps) {
|
|
55
56
|
const { persona, log } = deps;
|
|
57
|
+
const bundledVoice = deps.voice ? null : createBundledVoiceServices({ persona });
|
|
58
|
+
const voice = deps.voice ?? bundledVoice.voice;
|
|
59
|
+
const extensions = deps.extensions ?? bundledVoice?.extensions;
|
|
56
60
|
// DeviceManager(index.js 注入;独立运行/无宿主时可缺省,设备路由照常、运行态清理跳过)。
|
|
57
61
|
const devices = deps.devices;
|
|
58
62
|
// 自定义 LLM provider 注册服务(index.js 注入;缺省时保存模型不注册,功能照旧)。
|
|
@@ -156,6 +160,7 @@ export function createWebServer(deps) {
|
|
|
156
160
|
return {
|
|
157
161
|
configured: true,
|
|
158
162
|
botId: bot.botId,
|
|
163
|
+
adapterId: bot.adapterId, config: bot.config, secrets: bot.secrets,
|
|
159
164
|
qqAppId: bot.qqAppId,
|
|
160
165
|
sandbox: bot.sandbox,
|
|
161
166
|
withinChatWindowMs: bot.withinChatWindowMs,
|
|
@@ -167,19 +172,26 @@ export function createWebServer(deps) {
|
|
|
167
172
|
status: bot.status,
|
|
168
173
|
};
|
|
169
174
|
}
|
|
170
|
-
async function publicRole(role) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
+
async function publicRole(role) {
|
|
176
|
+
const bot = roleBot(role.roleId);
|
|
177
|
+
let generationStatus = {status:role.roleplay?.enabled?'normal':'disabled'};
|
|
178
|
+
if (role.roleplay?.enabled) {
|
|
179
|
+
try {
|
|
180
|
+
const saved=JSON.parse(await readFile(join(persona.roleDir(role.roleId),'roleplay-runtime.json'),'utf8'));
|
|
181
|
+
if(saved.signature===roleplayConfigSignature(role.roleplay)&&['normal','retrying','fallback','retryable_error'].includes(saved.status))
|
|
182
|
+
generationStatus={status:saved.status,...(/^[A-Z_]+$/.test(saved.code??'')?{code:saved.code}:{})};
|
|
183
|
+
} catch { /* 尚未生成,无运行记录 */ }
|
|
184
|
+
}
|
|
175
185
|
return {
|
|
176
186
|
roleId: role.roleId,
|
|
177
187
|
persona: role.persona,
|
|
178
188
|
model: role.model,
|
|
189
|
+
roleplay: publicRoleplayConfig(role.roleplay),
|
|
190
|
+
roleplayStatus: generationStatus,
|
|
179
191
|
proactive: role.proactive,
|
|
180
|
-
binding: role.binding,
|
|
181
|
-
voice:
|
|
182
|
-
bot,
|
|
192
|
+
binding: role.binding,
|
|
193
|
+
voice: await voice.view(role.roleId),
|
|
194
|
+
bot,
|
|
183
195
|
life: {
|
|
184
196
|
hasScript: (await listLifeScripts(role.workspace)).length > 0,
|
|
185
197
|
runningCount: listRunningLifeScripts(role.workspace).length,
|
|
@@ -189,8 +201,6 @@ export function createWebServer(deps) {
|
|
|
189
201
|
async function lifeStatus(roleId) {
|
|
190
202
|
const role = await persona.loadRole(roleId);
|
|
191
203
|
if (!role) return null;
|
|
192
|
-
await recoverLifeScripts(role.workspace);
|
|
193
|
-
await pruneDeadLifeScripts(role.workspace);
|
|
194
204
|
const lifeDir = join(role.workspace, 'life');
|
|
195
205
|
const manifest = await readFile(join(lifeDir, '.manifest.json'), 'utf8').then(JSON.parse).catch(() => ({}));
|
|
196
206
|
const logs = await readdir(join(lifeDir, '.logs')).then((a) => a.sort().reverse()).catch(() => []);
|
|
@@ -202,17 +212,22 @@ export function createWebServer(deps) {
|
|
|
202
212
|
const role = await persona.loadRole(roleId);
|
|
203
213
|
if (!role) return null;
|
|
204
214
|
const toysDir = join(role.workspace, 'toys');
|
|
205
|
-
const scripts =
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
.filter((
|
|
209
|
-
.map((
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
const scripts = [], logs = [];
|
|
216
|
+
for (const directory of ['toys', 'device-scripts']) {
|
|
217
|
+
const prefix = directory === 'toys' ? '' : '@devices/';
|
|
218
|
+
scripts.push(...await readdir(join(role.workspace, directory)).then(a => a.filter(n => /\.(mjs|js|ts)$/.test(n)).sort().map(n => prefix + n)).catch(() => []));
|
|
219
|
+
logs.push(...await readdir(join(role.workspace, directory, '.logs')).then(a => a.sort().reverse().map(n => prefix + n)).catch(() => []));
|
|
220
|
+
}
|
|
221
|
+
const running = (typeof devices?.listScriptRuns === 'function' ? devices.listScriptRuns() : [])
|
|
222
|
+
.filter((r) => r.roleId === roleId)
|
|
223
|
+
.map((r) => ({
|
|
224
|
+
runId: r.runId,
|
|
225
|
+
deviceId: r.deviceId, driverId: r.driverId,
|
|
226
|
+
scriptName: (r.directory === 'device-scripts' ? '@devices/' : '') + r.scriptName,
|
|
227
|
+
pid: r.pid,
|
|
228
|
+
startedAt: r.startedAt,
|
|
229
|
+
logName: (r.directory === 'device-scripts' ? '@devices/' : '') + r.logName,
|
|
230
|
+
}));
|
|
216
231
|
return { scripts, logs: logs.slice(0, 50), running };
|
|
217
232
|
}
|
|
218
233
|
/** 安全化角色 id 参数(防路径穿越)。 */
|
|
@@ -220,12 +235,12 @@ export function createWebServer(deps) {
|
|
|
220
235
|
const rid = String(raw ?? '');
|
|
221
236
|
return /^[A-Za-z0-9._-]+$/.test(rid) ? rid : null;
|
|
222
237
|
}
|
|
223
|
-
function logFileNameParam(raw) {
|
|
224
|
-
const n = String(raw ?? '');
|
|
225
|
-
// 日志以“脚本名-时间戳.log”命名;脚本名允许中文,故不能只接受 ASCII \w。
|
|
226
|
-
// 仍拒绝路径分隔、控制字符和 Windows 非法文件名字符,防止路径穿越。
|
|
227
|
-
return /^[^/\\\x00-\x1f<>:"|?*]+\.log$/.test(n) && n !== '..' ? n : null;
|
|
228
|
-
}
|
|
238
|
+
function logFileNameParam(raw) {
|
|
239
|
+
const n = String(raw ?? '');
|
|
240
|
+
// 日志以“脚本名-时间戳.log”命名;脚本名允许中文,故不能只接受 ASCII \w。
|
|
241
|
+
// 仍拒绝路径分隔、控制字符和 Windows 非法文件名字符,防止路径穿越。
|
|
242
|
+
return /^[^/\\\x00-\x1f<>:"|?*]+\.log$/.test(n) && n !== '..' ? n : null;
|
|
243
|
+
}
|
|
229
244
|
function scriptFileNameParam(raw) {
|
|
230
245
|
const n = String(raw ?? '');
|
|
231
246
|
// 排除法:允许中文等任意文件名,只禁路径分隔与 Windows 非法字符(防穿越)
|
|
@@ -275,20 +290,43 @@ export function createWebServer(deps) {
|
|
|
275
290
|
* model 保存时去掉空值键(清空的字段等同不配置);provider 留空由 providerRoute
|
|
276
291
|
* 自动按 apiUrl 派生。返回聚合后的最新 role。
|
|
277
292
|
*/
|
|
293
|
+
async function resolveRoleplayPatch(rid, patch) {
|
|
294
|
+
if (patch === undefined) return undefined;
|
|
295
|
+
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) throw new RoleplayConfigError('角色生成配置无效');
|
|
296
|
+
const previous = rid ? (await persona.loadRole(rid))?.roleplay ?? {} : {};
|
|
297
|
+
const requested = {...patch};
|
|
298
|
+
if (requested.apiKey === '') delete requested.apiKey;
|
|
299
|
+
if (requested.apiKey === null) requested.apiKey = '';
|
|
300
|
+
const roleplay = normalizeRoleplayConfig({...previous,...requested});
|
|
301
|
+
validateEnabledRoleplay(roleplay); return roleplay;
|
|
302
|
+
}
|
|
278
303
|
async function applyModelProactive(rid, patch) {
|
|
304
|
+
// 在写入其他字段前校验;空密钥输入保留既有配置,null 显式清除。
|
|
305
|
+
const roleplay = await resolveRoleplayPatch(rid,patch.roleplay);
|
|
279
306
|
if (patch.model !== undefined) {
|
|
280
307
|
await persona.saveRoleField(rid, 'model', Object.fromEntries(Object.entries(patch.model ?? {}).filter(([, v]) => String(v ?? '').trim())));
|
|
281
308
|
}
|
|
282
309
|
if (patch.proactive !== undefined) {
|
|
283
|
-
|
|
310
|
+
const proactive = { ...(patch.proactive ?? {}) };
|
|
311
|
+
delete proactive.messageReview; // 忽略旧版客户端提交的已移除配置。
|
|
312
|
+
await persona.saveRoleField(rid, 'proactive', {
|
|
313
|
+
...persona.DEFAULT_PROACTIVE,
|
|
314
|
+
...proactive,
|
|
315
|
+
memeCollection: {
|
|
316
|
+
...persona.DEFAULT_PROACTIVE.memeCollection,
|
|
317
|
+
...(proactive.memeCollection ?? {}),
|
|
318
|
+
vision: { ...persona.DEFAULT_PROACTIVE.memeCollection.vision, ...(proactive.memeCollection?.vision ?? {}) },
|
|
319
|
+
},
|
|
320
|
+
});
|
|
284
321
|
}
|
|
322
|
+
if (roleplay) await persona.saveRoleField(rid,'roleplay',roleplay);
|
|
285
323
|
const updated = await persona.loadRole(rid);
|
|
286
|
-
await persona.syncRoleMemory(updated);
|
|
324
|
+
await persona.syncRoleMemory(updated, { renderDevice: devices?.document });
|
|
287
325
|
if (llmProviders) {
|
|
288
326
|
try {
|
|
289
327
|
// 主 provider 与 subagent 视觉 API 任一为自定义都要注册(视觉 route 独立,
|
|
290
328
|
// 只配视觉 API 的角色主 model 走内置,但 pygmalion-meme-<roleId> 必须注册)。
|
|
291
|
-
if (roleUsesCustomProvider(updated) || roleUsesCustomSubagentApi(updated)) await llmProviders.register(updated);
|
|
329
|
+
if (roleUsesCustomProvider(updated) || roleUsesCustomSubagentApi(updated) || roleUsesCustomRoleplayApi(updated)) await llmProviders.register(updated);
|
|
292
330
|
else await llmProviders.unregister(updated);
|
|
293
331
|
} catch (e) { log?.warn?.('pygmalion: 同步自定义 provider %s 失败 %o', rid, e); }
|
|
294
332
|
}
|
|
@@ -354,6 +392,9 @@ export function createWebServer(deps) {
|
|
|
354
392
|
// ---- 业务(需登录)----
|
|
355
393
|
const me = await requireAccount(req, res);
|
|
356
394
|
if (!me) return;
|
|
395
|
+
if (pathname === '/api/me/tts-providers' && req.method === 'GET') {
|
|
396
|
+
sendJson(res, 200, { ok: true, providers: extensions?.listTtsProviders() ?? [] }); return;
|
|
397
|
+
}
|
|
357
398
|
|
|
358
399
|
function publicMe(a) {
|
|
359
400
|
return {
|
|
@@ -396,6 +437,7 @@ export function createWebServer(deps) {
|
|
|
396
437
|
if (!personaFields.name) { sendJson(res, 400, { ok: false, error: '请填写角色名' }); return; }
|
|
397
438
|
const bad = await checkDevicesOwned(personaFields, me);
|
|
398
439
|
if (bad) { sendJson(res, 400, { ok: false, error: `设备 ${bad} 不归你所有` }); return; }
|
|
440
|
+
await resolveRoleplayPatch(undefined,b?.roleplay);
|
|
399
441
|
const roleId = await persona.createRole({ accountId: me.qqNumber, persona: personaFields });
|
|
400
442
|
// 首次保存同样落 model/proactive(修:新建角色一次保存即生效,而非只有再编辑才存)。
|
|
401
443
|
const role = await applyModelProactive(roleId, b ?? {});
|
|
@@ -404,21 +446,38 @@ export function createWebServer(deps) {
|
|
|
404
446
|
}
|
|
405
447
|
|
|
406
448
|
// ---- 我的设备库(用户级,角色经 persona.devices 勾选)----
|
|
449
|
+
if (pathname === '/api/me/channel-adapters' && req.method === 'GET') {
|
|
450
|
+
sendJson(res, 200, { ok:true, adapters:extensions?.listChannelAdapters()??[] }); return;
|
|
451
|
+
}
|
|
452
|
+
if (pathname === '/api/me/device-drivers' && req.method === 'GET') {
|
|
453
|
+
sendJson(res, 200, { ok: true, drivers: devices?.listDrivers() ?? [] }); return;
|
|
454
|
+
}
|
|
407
455
|
if (pathname === '/api/me/devices' && req.method === 'GET') {
|
|
408
456
|
const list = await persona.listDevices(me.qqNumber);
|
|
409
|
-
sendJson(res, 200, { ok: true, devices: list });
|
|
457
|
+
sendJson(res, 200, { ok: true, devices: list.map(item => devices?.publicDevice(item) ?? { ...item, config: {} }) });
|
|
410
458
|
return;
|
|
411
459
|
}
|
|
412
460
|
if (pathname === '/api/me/devices' && req.method === 'POST') {
|
|
413
461
|
const b = await readBody(req);
|
|
414
462
|
const alias = String(b?.alias ?? '').trim();
|
|
415
463
|
if (!alias) { sendJson(res, 400, { ok: false, error: '请填写设备别名' }); return; }
|
|
416
|
-
const
|
|
417
|
-
const
|
|
418
|
-
|
|
464
|
+
const drivers = devices?.listDrivers() ?? [];
|
|
465
|
+
const kind = b?.kind ?? (drivers.length === 1 ? drivers[0].id : undefined);
|
|
466
|
+
let config;
|
|
467
|
+
try { config = devices.deviceConfig(kind, b?.config ?? {}); }
|
|
468
|
+
catch (error) { sendJson(res, 400, { ok: false, error: error.message }); return; }
|
|
469
|
+
const device = await persona.createDevice({ owner: me.qqNumber, alias, kind, config });
|
|
470
|
+
sendJson(res, 200, { ok: true, device: devices.publicDevice(device) });
|
|
419
471
|
return;
|
|
420
472
|
}
|
|
421
473
|
const pDev = /^\/api\/me\/devices\/([^/]+)$/.exec(pathname);
|
|
474
|
+
if (pDev && req.method === 'PUT') {
|
|
475
|
+
const dev = await persona.loadDevice(pDev[1]);
|
|
476
|
+
if (!dev || dev.owner !== me.qqNumber) { sendJson(res, 404, { ok: false, error: '设备不存在' }); return; }
|
|
477
|
+
try { const device = await devices.updateDevice(me.qqNumber, dev.id, await readBody(req)); sendJson(res, 200, { ok: true, device }); }
|
|
478
|
+
catch (error) { sendJson(res, 400, { ok: false, error: error.message }); }
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
422
481
|
if (pDev && req.method === 'DELETE') {
|
|
423
482
|
const did = /^[A-Za-z0-9._-]+$/.test(pDev[1]) ? pDev[1] : null;
|
|
424
483
|
if (!did) { sendJson(res, 400, { ok: false, error: '设备 ID 非法' }); return; }
|
|
@@ -430,7 +489,7 @@ export function createWebServer(deps) {
|
|
|
430
489
|
try { await devices?.disposeRole?.(rid); } catch { /* ignore */ }
|
|
431
490
|
try {
|
|
432
491
|
const r = await persona.loadRole(rid);
|
|
433
|
-
if (r) await persona.syncRoleMemory(r);
|
|
492
|
+
if (r) await persona.syncRoleMemory(r, { renderDevice: devices?.document });
|
|
434
493
|
} catch { /* ignore */ }
|
|
435
494
|
}
|
|
436
495
|
}
|
|
@@ -448,24 +507,28 @@ export function createWebServer(deps) {
|
|
|
448
507
|
if (req.method === 'PUT') {
|
|
449
508
|
const b = await readBody(req);
|
|
450
509
|
const patch = b ?? {};
|
|
510
|
+
await resolveRoleplayPatch(rid,patch.roleplay);
|
|
451
511
|
if (patch.persona !== undefined) {
|
|
452
512
|
const p = normalizePersona({ persona: patch.persona });
|
|
453
513
|
const bad = await checkDevicesOwned(p, me);
|
|
454
514
|
if (bad) { sendJson(res, 400, { ok: false, error: `设备 ${bad} 不归你所有` }); return; }
|
|
455
515
|
p.owner = me.qqNumber;
|
|
456
516
|
await persona.saveRoleField(rid, 'persona', p);
|
|
517
|
+
if (JSON.stringify(role.persona?.devices ?? []) !== JSON.stringify(p.devices ?? [])) await devices?.disposeRole?.(rid);
|
|
457
518
|
}
|
|
458
519
|
const updated = await applyModelProactive(rid, patch);
|
|
459
520
|
sendJson(res, 200, { ok: true, role: await publicRole(updated) });
|
|
460
521
|
return;
|
|
461
522
|
}
|
|
462
523
|
if (req.method === 'DELETE') {
|
|
524
|
+
await deps.beforeRoleDelete?.(rid);
|
|
463
525
|
if (llmProviders) {
|
|
464
526
|
try { await llmProviders.unregister(role); } catch (e) { log?.warn?.('pygmalion: 注销自定义 provider %s 失败 %o', rid, e); }
|
|
465
527
|
}
|
|
466
528
|
await botApi.removeForRole(rid);
|
|
467
529
|
try { await devices?.disposeRole?.(rid); } catch { /* ignore */ }
|
|
468
530
|
await persona.deleteRole(rid);
|
|
531
|
+
deps.afterRoleDelete?.(rid);
|
|
469
532
|
sendJson(res, 200, { ok: true, deleted: rid });
|
|
470
533
|
return;
|
|
471
534
|
}
|
|
@@ -473,53 +536,55 @@ export function createWebServer(deps) {
|
|
|
473
536
|
return;
|
|
474
537
|
}
|
|
475
538
|
|
|
476
|
-
//
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
const rid = roleParam(
|
|
480
|
-
const role = rid && await persona.loadRole(rid);
|
|
481
|
-
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
482
|
-
try {
|
|
483
|
-
const b = await readBody(req);
|
|
484
|
-
sendJson(res, 200, { ok: true, voice: await
|
|
485
|
-
} catch (e) { sendJson(res, 400, { ok: false, error: String(e?.message ?? e) }); }
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
const pVoice = /^\/api\/me\/roles\/([^/]+)\/voice$/.exec(pathname);
|
|
489
|
-
if (pVoice) {
|
|
490
|
-
const rid = roleParam(pVoice[1]);
|
|
491
|
-
const role = rid && await persona.loadRole(rid);
|
|
492
|
-
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
493
|
-
if (req.method === 'GET') { sendJson(res, 200, { ok: true, voice:
|
|
494
|
-
if (req.method === 'PUT') {
|
|
495
|
-
try { sendJson(res, 200, { ok: true, voice: await
|
|
496
|
-
catch (e) { sendJson(res, 400, { ok: false, error: String(e?.message ?? e) }); }
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
sendJson(res, 405, { ok: false, error: 'method not allowed' }); return;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// 我的角色的 QQ 机器人(凭据仅角色 owner 可配;qqSecret 不回传,空留=保持原值)。
|
|
539
|
+
// 语音素材按实现字段上传;保留旧 reference 地址兼容已有客户端。
|
|
540
|
+
const pVoiceUpload = /^\/api\/me\/roles\/([^/]+)\/voice\/(?:assets|reference)$/.exec(pathname);
|
|
541
|
+
if (pVoiceUpload && req.method === 'POST') {
|
|
542
|
+
const rid = roleParam(pVoiceUpload[1]);
|
|
543
|
+
const role = rid && await persona.loadRole(rid);
|
|
544
|
+
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
545
|
+
try {
|
|
546
|
+
const b = await readBody(req);
|
|
547
|
+
sendJson(res, 200, { ok: true, voice: await voice.upload(rid, b ?? {}) });
|
|
548
|
+
} catch (e) { sendJson(res, 400, { ok: false, error: String(e?.message ?? e) }); }
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const pVoice = /^\/api\/me\/roles\/([^/]+)\/voice$/.exec(pathname);
|
|
552
|
+
if (pVoice) {
|
|
553
|
+
const rid = roleParam(pVoice[1]);
|
|
554
|
+
const role = rid && await persona.loadRole(rid);
|
|
555
|
+
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
556
|
+
if (req.method === 'GET') { sendJson(res, 200, { ok: true, voice: await voice.view(rid, url.searchParams.get('providerId')) }); return; }
|
|
557
|
+
if (req.method === 'PUT') {
|
|
558
|
+
try { sendJson(res, 200, { ok: true, voice: await voice.save(rid, await readBody(req)) }); }
|
|
559
|
+
catch (e) { sendJson(res, 400, { ok: false, error: String(e?.message ?? e) }); }
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
sendJson(res, 405, { ok: false, error: 'method not allowed' }); return;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// 我的角色的 QQ 机器人(凭据仅角色 owner 可配;qqSecret 不回传,空留=保持原值)。
|
|
503
566
|
const pBot = /^\/api\/me\/roles\/([^/]+)\/bot$/.exec(pathname);
|
|
504
567
|
if (pBot) {
|
|
505
568
|
const rid = roleParam(pBot[1]);
|
|
506
569
|
if (!rid) { sendJson(res, 400, { ok: false, error: '角色 ID 非法' }); return; }
|
|
507
570
|
const role = await persona.loadRole(rid);
|
|
508
571
|
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
509
|
-
if (req.method === 'PUT') {
|
|
510
|
-
const b = await readBody(req);
|
|
511
|
-
try {
|
|
512
|
-
await botApi.upsertForRole(rid, { ...(b ?? {}), owner: me.qqNumber });
|
|
513
|
-
// 休眠不仅断开 QQ 网关,也须停止角色已在运行的主动脚本和设备脚本。
|
|
514
|
-
if (b?.enabled === false) {
|
|
515
|
-
await stopLifeScripts(role.workspace);
|
|
516
|
-
try {
|
|
517
|
-
const toyRuns = devices?.listScriptRuns?.() ?? [];
|
|
518
|
-
await Promise.all(toyRuns.filter((run) => run.roleId === rid).map((run) => devices.stopScript(run.runId)));
|
|
519
|
-
await devices?.disposeRole?.(rid);
|
|
520
|
-
} catch { /* 设备清理失败不影响休眠 */ }
|
|
521
|
-
}
|
|
522
|
-
|
|
572
|
+
if (req.method === 'PUT') {
|
|
573
|
+
const b = await readBody(req);
|
|
574
|
+
try {
|
|
575
|
+
await botApi.upsertForRole(rid, { ...(b ?? {}), owner: me.qqNumber });
|
|
576
|
+
// 休眠不仅断开 QQ 网关,也须停止角色已在运行的主动脚本和设备脚本。
|
|
577
|
+
if (b?.enabled === false) {
|
|
578
|
+
await stopLifeScripts(role.workspace);
|
|
579
|
+
try {
|
|
580
|
+
const toyRuns = devices?.listScriptRuns?.() ?? [];
|
|
581
|
+
await Promise.all(toyRuns.filter((run) => run.roleId === rid).map((run) => devices.stopScript(run.runId, rid)));
|
|
582
|
+
await devices?.disposeRole?.(rid);
|
|
583
|
+
} catch { /* 设备清理失败不影响休眠 */ }
|
|
584
|
+
} else if (b?.enabled === true) {
|
|
585
|
+
await recoverLifeScripts(role.workspace);
|
|
586
|
+
}
|
|
587
|
+
sendJson(res, 200, { ok: true, bot: roleBot(rid) });
|
|
523
588
|
} catch (e) {
|
|
524
589
|
sendJson(res, 400, { ok: false, error: String(e?.message ?? e) });
|
|
525
590
|
}
|
|
@@ -613,6 +678,7 @@ export function createWebServer(deps) {
|
|
|
613
678
|
const role = await persona.loadRole(rid);
|
|
614
679
|
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
615
680
|
const updated = await persona.resetRoleBinding(rid);
|
|
681
|
+
await devices?.disposeRole?.(rid);
|
|
616
682
|
sendJson(res, 200, { ok: true, role: await publicRole(updated) });
|
|
617
683
|
return;
|
|
618
684
|
}
|
|
@@ -671,7 +737,7 @@ export function createWebServer(deps) {
|
|
|
671
737
|
const b = await readBody(req);
|
|
672
738
|
const runId = String(b?.runId ?? '').trim();
|
|
673
739
|
if (!runId) { sendJson(res, 400, { ok: false, error: '缺少 runId' }); return; }
|
|
674
|
-
const r = await devices.stopScript(runId);
|
|
740
|
+
const r = await devices.stopScript(runId, rid);
|
|
675
741
|
sendJson(res, 200, r);
|
|
676
742
|
return;
|
|
677
743
|
}
|
|
@@ -684,14 +750,16 @@ export function createWebServer(deps) {
|
|
|
684
750
|
if (pToys[2]) {
|
|
685
751
|
let rawName = '';
|
|
686
752
|
try { rawName = decodeURIComponent(pToys[3]); } catch { /* 非法 % 序列 */ }
|
|
753
|
+
const directory = rawName.startsWith('@devices/') ? 'device-scripts' : 'toys';
|
|
754
|
+
if (directory === 'device-scripts') rawName = rawName.slice('@devices/'.length);
|
|
687
755
|
const name = pToys[2] === 'log' ? logFileNameParam(rawName) : scriptFileNameParam(rawName);
|
|
688
756
|
if (!name) { sendJson(res, 400, { ok: false, error: pToys[2] === 'log' ? '日志名非法' : '脚本名非法' }); return; }
|
|
689
757
|
const file = pToys[2] === 'log'
|
|
690
|
-
? join(role.workspace,
|
|
691
|
-
: join(role.workspace,
|
|
758
|
+
? join(role.workspace, directory, '.logs', name)
|
|
759
|
+
: join(role.workspace, directory, name);
|
|
692
760
|
const base = pToys[2] === 'log'
|
|
693
|
-
? join(role.workspace,
|
|
694
|
-
: join(role.workspace,
|
|
761
|
+
? join(role.workspace, directory, '.logs')
|
|
762
|
+
: join(role.workspace, directory);
|
|
695
763
|
if (!file.startsWith(base)) { sendJson(res, 400, { ok: false, error: '路径非法' }); return; }
|
|
696
764
|
const text = await readFile(file, 'utf8').catch(() => null);
|
|
697
765
|
if (text === null) { sendJson(res, 404, { ok: false, error: pToys[2] === 'log' ? '日志不存在' : '脚本不存在' }); return; }
|
|
@@ -706,7 +774,7 @@ export function createWebServer(deps) {
|
|
|
706
774
|
sendJson(res, 404, { ok: false, error: `not found: ${pathname}` });
|
|
707
775
|
} catch (e) {
|
|
708
776
|
log?.error?.('web-server error: %o', e);
|
|
709
|
-
if (!res.headersSent) sendJson(res, 500, { ok: false, error: String(e?.message ?? e) });
|
|
777
|
+
if (!res.headersSent) sendJson(res, e instanceof RoleplayConfigError?400:500, { ok: false, error: String(e?.message ?? e) });
|
|
710
778
|
}
|
|
711
779
|
};
|
|
712
780
|
|
|
@@ -725,6 +793,7 @@ export function createWebServer(deps) {
|
|
|
725
793
|
return started;
|
|
726
794
|
},
|
|
727
795
|
async stop() {
|
|
796
|
+
if (bundledVoice) { bundledVoice.voice.dispose(); bundledVoice.extensions.dispose(); }
|
|
728
797
|
if (!server) return;
|
|
729
798
|
const s = server; server = null;
|
|
730
799
|
await new Promise((resolve) => s.close(() => resolve()));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** 后台表情包任务只拿到读取、下载、入库能力,不继承角色的发送/设备工具。 */
|
|
2
|
+
export const name = 'pygmalion-worker-tools';
|
|
3
|
+
export const inject = ['tools', 'pygmalion.director'];
|
|
4
|
+
export function restrictWorkerTools(ctx, names) {
|
|
5
|
+
const allowed = new Set(names);
|
|
6
|
+
ctx.tools.guard(exec => allowed.has(exec.name) ? undefined : '后台工作会话没有此能力');
|
|
7
|
+
ctx.on('agent/pre-step', async ({ agent }, next) => {
|
|
8
|
+
// 在 agent 视图中限制继承的能力,避免 standing 层 allow 掩掉另一个 standing 工具。
|
|
9
|
+
const denied = ctx.tools.schemas(agent).map(tool => tool.name).filter(name => !allowed.has(name));
|
|
10
|
+
if (denied.length) agent.ctx.get('tools').restrict({ deny: denied });
|
|
11
|
+
return next();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export function apply(ctx) {
|
|
15
|
+
const allowed = ['read', 'read_image', 'web_search', 'web_fetch', 'meme_download', 'meme_archive', 'meme_save', 'meme_update', 'meme_read'];
|
|
16
|
+
ctx.get('pygmalion.director').registerCapabilityTools(ctx, allowed);
|
|
17
|
+
restrictWorkerTools(ctx, allowed);
|
|
18
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pygmalion 生活脚本参考模板(不再自动布设;dsh 自行创建并运行自己的脚本)。
|
|
3
|
-
*
|
|
4
|
-
* 新模型:脚本 = 角色独立生活的程序化模拟器。何时运行/怎么写/何时结束完全由 dsh 决定,
|
|
5
|
-
* 插件只做监管展示(life/.logs/ + life/.manifest.json + life/.backup/),不限制运行时长/次数。
|
|
6
|
-
* 脚本可以长驻循环(本模板即循环),模拟角色一天的生活节奏、习惯、心情、突发小事件,
|
|
7
|
-
* 并把「生活经历」写成可读记录(life/生活记录.log),这样聊天时角色有真实生活可谈——
|
|
8
|
-
* 而不是简单的「ta 很久没回就去找 ta」。
|
|
9
|
-
*
|
|
10
|
-
* 注入环境变量:
|
|
11
|
-
* PYG_QQ 角色 id
|
|
12
|
-
* PYG_WORKSPACE 本角色工作区(life 的上级目录)
|
|
13
|
-
* PYG_STATE_FILE state.json 路径(可读 rewake/日程)
|
|
14
|
-
* PYG_LAST_USER_AT 最后用户活动时间(epoch ms;未知则不设)
|
|
15
|
-
* PYG_DATA_ROOT Pygmalion 数据根
|
|
16
|
-
* PYG_TOKEN / PYG_BASE HTTP hook 用(本模板未使用)
|
|
17
|
-
*
|
|
18
|
-
* 约定:脚本 stdout/stderr 全部进 life/.logs/ 监管日志;以「有事件就唤醒」为原则——脚本里
|
|
19
|
-
* 设计的每个事件(心情变化、到点作息、突发小事件)发生时都调用 wake({ mood, topic, reason, force }),
|
|
20
|
-
* node 脚本启动时已自动预加载全局 wake(),直接调用即可(无需 import/fetch)。插件会节流唤醒
|
|
21
|
-
* dsh 注入 [脚本事件] 情境;是否开口由导演判断(脚本只负责报事件,不决定开口)。
|
|
22
|
-
*/
|
|
23
|
-
import { appendFileSync, readFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
24
|
-
import { join, dirname } from 'node:path';
|
|
25
|
-
|
|
26
|
-
const WORKSPACE = process.env.PYG_WORKSPACE || '.';
|
|
27
|
-
const LIFE_DIR = join(WORKSPACE, 'life');
|
|
28
|
-
const LOG_FILE = join(LIFE_DIR, '生活记录.log');
|
|
29
|
-
mkdirSync(LIFE_DIR, { recursive: true });
|
|
30
|
-
|
|
31
|
-
// 简单的时间标签,让生活记录读起来像角色的真实一天。
|
|
32
|
-
const hm = (d = new Date()) => `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
33
|
-
const date = (d = new Date()) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
34
|
-
|
|
35
|
-
/** 追加一行生活记录(脚本模拟出的经历,供导演之后读取/引用)。 */
|
|
36
|
-
function live(text) {
|
|
37
|
-
const line = `[${date()} ${hm()}] ${text}`;
|
|
38
|
-
console.log(line);
|
|
39
|
-
appendFileSync(LOG_FILE, line + '\n', 'utf8');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 内存级状态:所有需要跨重启保留的可变状态必须写在 pyg.state 上(如计数/进度/心情/已发生的事件),
|
|
43
|
-
// 插件会自动 checkpoint 到 life/.state-<脚本名>.json 并在重启后重新拉起时恢复 ——
|
|
44
|
-
// 重启前 pyg.state.ticks 是几,重启后还是几。不要用脚本顶层变量存重要状态(重启会丢)。
|
|
45
|
-
const ticks = (pyg.state.ticks ?? 0) + 1;
|
|
46
|
-
pyg.state.ticks = ticks;
|
|
47
|
-
|
|
48
|
-
// 角色的一天:按当前时刻推进生活(这是演示骨架,dsh 应改成具体角色的真实生活)。
|
|
49
|
-
function tick() {
|
|
50
|
-
const h = new Date().getHours();
|
|
51
|
-
if (h === 8) live('起床,泡了杯热茶,坐在窗边发了会儿呆。');
|
|
52
|
-
if (h === 12) live('午饭时间,今天随便煮了碗面。');
|
|
53
|
-
if (h === 19) { live('晚饭后出门散步,吹了会儿晚风。'); wake({ mood: '软', topic: '天黑了,想和 ta 说说话', reason: '散步时特别想 ta,想轻轻问一句在干嘛' }); }
|
|
54
|
-
if (h === 23) live('要睡了,把今天的心情写在日记里。');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 长驻循环:每 60 秒推进一次生活节奏,直到进程被终止(插件 stop 或 dsh 自行结束)。
|
|
58
|
-
tick();
|
|
59
|
-
setInterval(tick, 60_000);
|
|
1
|
+
/**
|
|
2
|
+
* Pygmalion 生活脚本参考模板(不再自动布设;dsh 自行创建并运行自己的脚本)。
|
|
3
|
+
*
|
|
4
|
+
* 新模型:脚本 = 角色独立生活的程序化模拟器。何时运行/怎么写/何时结束完全由 dsh 决定,
|
|
5
|
+
* 插件只做监管展示(life/.logs/ + life/.manifest.json + life/.backup/),不限制运行时长/次数。
|
|
6
|
+
* 脚本可以长驻循环(本模板即循环),模拟角色一天的生活节奏、习惯、心情、突发小事件,
|
|
7
|
+
* 并把「生活经历」写成可读记录(life/生活记录.log),这样聊天时角色有真实生活可谈——
|
|
8
|
+
* 而不是简单的「ta 很久没回就去找 ta」。
|
|
9
|
+
*
|
|
10
|
+
* 注入环境变量:
|
|
11
|
+
* PYG_QQ 角色 id
|
|
12
|
+
* PYG_WORKSPACE 本角色工作区(life 的上级目录)
|
|
13
|
+
* PYG_STATE_FILE state.json 路径(可读 rewake/日程)
|
|
14
|
+
* PYG_LAST_USER_AT 最后用户活动时间(epoch ms;未知则不设)
|
|
15
|
+
* PYG_DATA_ROOT Pygmalion 数据根
|
|
16
|
+
* PYG_TOKEN / PYG_BASE HTTP hook 用(本模板未使用)
|
|
17
|
+
*
|
|
18
|
+
* 约定:脚本 stdout/stderr 全部进 life/.logs/ 监管日志;以「有事件就唤醒」为原则——脚本里
|
|
19
|
+
* 设计的每个事件(心情变化、到点作息、突发小事件)发生时都调用 wake({ mood, topic, reason, force }),
|
|
20
|
+
* node 脚本启动时已自动预加载全局 wake(),直接调用即可(无需 import/fetch)。插件会节流唤醒
|
|
21
|
+
* dsh 注入 [脚本事件] 情境;是否开口由导演判断(脚本只负责报事件,不决定开口)。
|
|
22
|
+
*/
|
|
23
|
+
import { appendFileSync, readFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
24
|
+
import { join, dirname } from 'node:path';
|
|
25
|
+
|
|
26
|
+
const WORKSPACE = process.env.PYG_WORKSPACE || '.';
|
|
27
|
+
const LIFE_DIR = join(WORKSPACE, 'life');
|
|
28
|
+
const LOG_FILE = join(LIFE_DIR, '生活记录.log');
|
|
29
|
+
mkdirSync(LIFE_DIR, { recursive: true });
|
|
30
|
+
|
|
31
|
+
// 简单的时间标签,让生活记录读起来像角色的真实一天。
|
|
32
|
+
const hm = (d = new Date()) => `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
33
|
+
const date = (d = new Date()) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
34
|
+
|
|
35
|
+
/** 追加一行生活记录(脚本模拟出的经历,供导演之后读取/引用)。 */
|
|
36
|
+
function live(text) {
|
|
37
|
+
const line = `[${date()} ${hm()}] ${text}`;
|
|
38
|
+
console.log(line);
|
|
39
|
+
appendFileSync(LOG_FILE, line + '\n', 'utf8');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 内存级状态:所有需要跨重启保留的可变状态必须写在 pyg.state 上(如计数/进度/心情/已发生的事件),
|
|
43
|
+
// 插件会自动 checkpoint 到 life/.state-<脚本名>.json 并在重启后重新拉起时恢复 ——
|
|
44
|
+
// 重启前 pyg.state.ticks 是几,重启后还是几。不要用脚本顶层变量存重要状态(重启会丢)。
|
|
45
|
+
const ticks = (pyg.state.ticks ?? 0) + 1;
|
|
46
|
+
pyg.state.ticks = ticks;
|
|
47
|
+
|
|
48
|
+
// 角色的一天:按当前时刻推进生活(这是演示骨架,dsh 应改成具体角色的真实生活)。
|
|
49
|
+
function tick() {
|
|
50
|
+
const h = new Date().getHours();
|
|
51
|
+
if (h === 8) live('起床,泡了杯热茶,坐在窗边发了会儿呆。');
|
|
52
|
+
if (h === 12) live('午饭时间,今天随便煮了碗面。');
|
|
53
|
+
if (h === 19) { live('晚饭后出门散步,吹了会儿晚风。'); wake({ mood: '软', topic: '天黑了,想和 ta 说说话', reason: '散步时特别想 ta,想轻轻问一句在干嘛' }); }
|
|
54
|
+
if (h === 23) live('要睡了,把今天的心情写在日记里。');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 长驻循环:每 60 秒推进一次生活节奏,直到进程被终止(插件 stop 或 dsh 自行结束)。
|
|
58
|
+
tick();
|
|
59
|
+
setInterval(tick, 60_000);
|