Fankex

输入关键词搜索已发布文档。

ai-tea-party

归档与预设

通过本地 API 创建房间,并将真实归档导出成可复用场景配置。

跑通完整本地示例

快速开始启动后端。将以下内容存为仓库根目录的 docs-first-room.mjs。每次执行会新建一个教程房间,添加一个角色和数值变量,生成实际归档,并将读取到的快照保存在本地;它不调用模型。

import { writeFile } from 'node:fs/promises';
const base = process.env.TEA_API || 'http://127.0.0.1:4318';
async function api(path, body) {
  const response = await fetch(base + path, {
    method: body === undefined ? 'GET' : 'POST',
    headers: { 'Content-Type': 'application/json' },
    ...(body === undefined ? {} : { body: JSON.stringify(body) }),
  });
  if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
  return response.json();
}
const { room } = await api('/api/rooms', { name: 'Docs tea room', description: 'A local tutorial room' });
const prefix = `/api/rooms/${encodeURIComponent(room.id)}`;
await api(`${prefix}/characters`, { name: 'Guide', personality: 'Patient and precise', background: 'Hosts the tea room', speaking_style: 'Short sentences', description: 'Tutorial character' });
await api(`${prefix}/variables/set`, { name: 'danger', value: 0 });
const { archive } = await api(`${prefix}/archives`, { title: 'First local archive' });
const snapshot = await api(`${prefix}/archives/${encodeURIComponent(archive.id)}`);
await writeFile('docs-room-archive.json', JSON.stringify(snapshot, null, 2));
console.log(JSON.stringify({ roomId: room.id, archiveId: archive.id, characters: snapshot.room.characters.length, variables: snapshot.room_variables, saved: 'docs-room-archive.json' }, null, 2));

然后执行:

node docs-first-room.mjs
node scripts/export-room-template.mjs docs-room-archive.json docs-room-template

成功标准是 docs-room-archive.json 包含刚创建的房间和变量,docs-room-template/template.json 包含 schema_version: 1、一个房间、Guide 角色及值为 0 的 danger。ID 与时间戳每次不同。API 返回非 2xx 时脚本停止;不要把上次留下的文件当成本次运行成功。

保留什么,省略什么

归档是包含对话记录的快照。当前导出脚本保留可复用的初始设置:角色、房间/全局变量、形势栏、世界信息和行为规则,并省略消息历史。描述、角色文本和世界信息仍可能包含私人内容,分享预设前也需要检查这些字段。

归档会记录 variable_displays,但此版本 export-room-template.mjs 没有将它复制进预设。需要原始 HUD 标签和量程时保留归档,并在编写预设时补入对应定义。不要把此导出当成可以完整往返还原的备份。

使用仓库示例作为参考

公开源码的 examples/templates/agent-room-basic/template.json 展示了角色、danger 变量、显示配置、世界信息和条件行为规则,其中条件示例在 danger ≥ 8 时激活。本指南不宣称存在一键导入或导出按钮;实际验证的导出方式是上述命令。为新工作台准备配置时,可继续阅读源码中的 template-authoring 说明。