輸入關鍵字搜尋已發布文件。
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 說明。