1. Conversation trails for an AI chat app
A chat app wants to store complete user + AI history in a way that is replayable, merge-safe across devices, and friendly to EarthCloud + model workflows.
Flow
- User sends a message.
- App creates a
turn event and appends it to Tongbuku 同步库. - EarthCloud parses the text into a GlyphIR block and emits its own events.
- Model responses and tool calls are appended as additional events.
- All devices sync using
/v1/sync and trail heads.
Benefits
- Full, ordered, replayable history for each conversation.
- Ability to reconstruct context windows for models at any point.
- Offline-friendly: devices can continue and merge later.
Example: appending a user turn
// Pseudo-code: append a user turn event
const event = {
event_id: "evt_turn_001",
trail_id: "trail_chat_abc",
kind: "turn",
timestamp: new Date().toISOString(),
parents: ["evt_turn_000"],
actors: {
user_id: "user_en",
app_id: "chat_app"
},
payload: {
type: "text_turn",
role: "user",
text: "Can you summarize this for my Chinese colleague?",
lang: "en",
glyphir_id: "gph_01HX..."
}
};
await fetch("https://tongbuku.example.com/v1/events/append", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <token>"
},
body: JSON.stringify({ events: [event] })
});