pygmalion 0.1.6 → 0.1.7
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/package.json +1 -1
- package/preset/pygmalion-director/agent.cordis.yml +120 -77
- package/src/agent-life.js +94 -17
- package/src/bot-factory.js +3 -0
- package/src/heartbeat.js +60 -1
- package/src/inbound.js +28 -8
- package/src/index.js +29 -9
- package/src/llm-provider.js +71 -27
- package/src/meme-worker.js +397 -0
- package/src/memebox.js +348 -0
- package/src/persona.js +20 -3
- package/src/setup-agent.js +3 -1
- package/src/tools.js +394 -1
- package/src/wakeup.js +0 -6
- package/src/web-public/app.js +107 -0
- package/src/web-public/index.html +27 -0
- package/src/web-public/style.css +7 -0
- package/src/web-server.js +77 -2
- package/templates/sample-life.mjs +6 -0
package/src/web-public/style.css
CHANGED
|
@@ -42,3 +42,10 @@ button:disabled { opacity: .5; cursor: default; }
|
|
|
42
42
|
.status-bar { background: var(--ok); color: #04140a; border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
|
|
43
43
|
.status-bar.error { background: var(--danger); color: #fff; }
|
|
44
44
|
ul { margin: 4px 0; padding-left: 20px; color: var(--muted); }
|
|
45
|
+
/* 表情包 */
|
|
46
|
+
.meme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
|
|
47
|
+
.meme-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
|
|
48
|
+
.meme-card img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #222; display: block; }
|
|
49
|
+
.meme-meta { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
|
|
50
|
+
.meme-meta label { font-size: 12px; }
|
|
51
|
+
.meme-meta input { font-size: 12px; padding: 5px 7px; }
|
package/src/web-server.js
CHANGED
|
@@ -35,7 +35,8 @@ import { join, extname } from 'node:path';
|
|
|
35
35
|
import { fileURLToPath } from 'node:url';
|
|
36
36
|
import path from 'node:path';
|
|
37
37
|
import { listLifeScripts, listRunningLifeScripts, stopLifeScript, recoverLifeScripts, pruneDeadLifeScripts } from './agent-life.js';
|
|
38
|
-
import { roleUsesCustomProvider } from './llm-provider.js';
|
|
38
|
+
import { roleUsesCustomProvider, roleUsesCustomSubagentApi } from './llm-provider.js';
|
|
39
|
+
import { listMemes, saveMeme, updateMeme, deleteMeme, memeFileFor } from './memebox.js';
|
|
39
40
|
|
|
40
41
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
41
42
|
const PUBLIC_DIR = join(__dirname, 'web-public');
|
|
@@ -248,7 +249,9 @@ export function createWebServer(deps) {
|
|
|
248
249
|
await persona.syncRoleMemory(updated);
|
|
249
250
|
if (llmProviders) {
|
|
250
251
|
try {
|
|
251
|
-
|
|
252
|
+
// 主 provider 与 subagent 视觉 API 任一为自定义都要注册(视觉 route 独立,
|
|
253
|
+
// 只配视觉 API 的角色主 model 走内置,但 pygmalion-meme-<roleId> 必须注册)。
|
|
254
|
+
if (roleUsesCustomProvider(updated) || roleUsesCustomSubagentApi(updated)) await llmProviders.register(updated);
|
|
252
255
|
else await llmProviders.unregister(updated);
|
|
253
256
|
} catch (e) { log?.warn?.('pygmalion: 同步自定义 provider %s 失败 %o', rid, e); }
|
|
254
257
|
}
|
|
@@ -419,6 +422,78 @@ export function createWebServer(deps) {
|
|
|
419
422
|
return;
|
|
420
423
|
}
|
|
421
424
|
|
|
425
|
+
// ---- 表情包库(memebox)管理:列表 / 批量上传 / 编辑 / 删除 / 图片 ----
|
|
426
|
+
const pMemeImage = /^\/api\/me\/roles\/([^/]+)\/memes\/([^/]+)\/image$/.exec(pathname);
|
|
427
|
+
if (pMemeImage && req.method === 'GET') {
|
|
428
|
+
const rid = roleParam(pMemeImage[1]);
|
|
429
|
+
const role = await persona.loadRole(rid);
|
|
430
|
+
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
431
|
+
const file = await memeFileFor(persona.roleWorkspace(rid), pMemeImage[2]);
|
|
432
|
+
if (!file) { sendJson(res, 404, { ok: false, error: '表情包不存在' }); return; }
|
|
433
|
+
try {
|
|
434
|
+
const data = await readFile(file);
|
|
435
|
+
const ext = extname(file).slice(1).toLowerCase();
|
|
436
|
+
const mime = ext === 'jpg' ? 'image/jpeg' : ext === 'png' ? 'image/png' : ext === 'webp' ? 'image/webp' : ext === 'gif' ? 'image/gif' : 'application/octet-stream';
|
|
437
|
+
res.writeHead(200, { 'content-type': mime, 'cache-control': 'private, max-age=3600' });
|
|
438
|
+
res.end(data);
|
|
439
|
+
} catch (e) { sendJson(res, 500, { ok: false, error: '读取表情包失败' }); }
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const pMemeOne = /^\/api\/me\/roles\/([^/]+)\/memes\/([^/]+)$/.exec(pathname);
|
|
443
|
+
if (pMemeOne) {
|
|
444
|
+
const rid = roleParam(pMemeOne[1]);
|
|
445
|
+
const role = await persona.loadRole(rid);
|
|
446
|
+
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
447
|
+
if (req.method === 'PUT') {
|
|
448
|
+
const b = await readBody(req);
|
|
449
|
+
const r = await updateMeme(persona.roleWorkspace(rid), pMemeOne[2], {
|
|
450
|
+
content: b?.content, style: b?.style, contexts: b?.contexts, name: b?.name,
|
|
451
|
+
});
|
|
452
|
+
if (!r.ok) { sendJson(res, 404, { ok: false, error: r.error }); return; }
|
|
453
|
+
sendJson(res, 200, { ok: true, entry: r.entry });
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (req.method === 'DELETE') {
|
|
457
|
+
const r = await deleteMeme(persona.roleWorkspace(rid), pMemeOne[2]);
|
|
458
|
+
if (!r.ok) { sendJson(res, 404, { ok: false, error: r.error }); return; }
|
|
459
|
+
sendJson(res, 200, { ok: true, deleted: pMemeOne[2] });
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
sendJson(res, 405, { ok: false, error: 'method not allowed' });
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const pMemes = /^\/api\/me\/roles\/([^/]+)\/memes$/.exec(pathname);
|
|
466
|
+
if (pMemes) {
|
|
467
|
+
const rid = roleParam(pMemes[1]);
|
|
468
|
+
const role = await persona.loadRole(rid);
|
|
469
|
+
if (!role || !ownedBy(role, me.qqNumber)) { sendJson(res, 404, { ok: false, error: '角色不存在' }); return; }
|
|
470
|
+
if (req.method === 'GET') {
|
|
471
|
+
sendJson(res, 200, { ok: true, memes: await listMemes(persona.roleWorkspace(rid)) });
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (req.method === 'POST') {
|
|
475
|
+
const b = await readBody(req);
|
|
476
|
+
const list = Array.isArray(b?.memes) ? b.memes : [];
|
|
477
|
+
const saved = [];
|
|
478
|
+
for (const m of list) {
|
|
479
|
+
if (!m || typeof m.data !== 'string' || m.data.length === 0) { saved.push({ ok: false, error: '缺少 data(base64)' }); continue; }
|
|
480
|
+
try {
|
|
481
|
+
const mediaType = /^image\/(png|jpeg|webp|gif)$/.test(String(m.mediaType ?? '')) ? m.mediaType : 'image/png';
|
|
482
|
+
const r = await saveMeme({
|
|
483
|
+
workspace: persona.roleWorkspace(rid),
|
|
484
|
+
source: `data:${mediaType};base64,${m.data}`,
|
|
485
|
+
name: m.name, content: m.content, style: m.style, contexts: m.contexts, log,
|
|
486
|
+
});
|
|
487
|
+
saved.push({ ok: true, memeId: r.memeId, file: r.file, status: r.status });
|
|
488
|
+
} catch (e) { saved.push({ ok: false, error: String(e?.message ?? e) }); }
|
|
489
|
+
}
|
|
490
|
+
sendJson(res, 200, { ok: true, saved });
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
sendJson(res, 405, { ok: false, error: 'method not allowed' });
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
|
|
422
497
|
const pReset = /^\/api\/me\/roles\/([^/]+)\/reset-binding$/.exec(pathname);
|
|
423
498
|
if (pReset && req.method === 'POST') {
|
|
424
499
|
const rid = roleParam(pReset[1]);
|
|
@@ -39,6 +39,12 @@ function live(text) {
|
|
|
39
39
|
appendFileSync(LOG_FILE, line + '\n', 'utf8');
|
|
40
40
|
}
|
|
41
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
|
+
|
|
42
48
|
// 角色的一天:按当前时刻推进生活(这是演示骨架,dsh 应改成具体角色的真实生活)。
|
|
43
49
|
function tick() {
|
|
44
50
|
const h = new Date().getHours();
|