EXAMPLES

Integration patterns

These examples show how Tongbuku 同步库 can back conversations, multi-device editing, and model workflows with trails and sync.

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

  1. User sends a message.
  2. App creates a turn event and appends it to Tongbuku 同步库.
  3. EarthCloud parses the text into a GlyphIR block and emits its own events.
  4. Model responses and tool calls are appended as additional events.
  5. 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] })
});

2. Multi-device editing with Merkle heads

A notes app uses Tongbuku 同步库 to sync edits across devices without building its own CRDT logic from scratch. Each edit is an event; the app derives document content from the trail.

Flow

  1. Each device maintains a local copy of the trail head.
  2. Edits (insert, delete, format) are encoded as events with parents.
  3. Devices periodically call /v1/sync with their merkle heads.
  4. The server returns missing events; devices merge locally.

Pattern

  • Trail per document: trail_id = "doc_{id}".
  • Events payloads: small deltas, not whole documents.
  • Views: server-side or client-side reconstruction + snapshotting.

Example: sync request

// Pseudo-code: client syncing a document trail
const res = await fetch("https://tongbuku.example.com/v1/sync", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    heads: [
      {
        trail_id: "trail_doc_123",
        merkle_hash: localMerkleHash
      }
    ],
    limit: 128
  })
});

const { trails } = await res.json();
for (const trail of trails) {
  applyEventsToLocalDoc(trail.events);
  updateLocalHead(trail.server_head.merkle_hash, trail.server_head.last_event_id);
}

3. Model workflows & dataset extraction

An AI team wants to generate training/eval datasets from real trails without bespoke ETL for each product surface.

Flow

  1. Products append events to Tongbuku 同步库 trails.
  2. A batch job queries trails by tags (e.g., domain:docs, plan:pro).
  3. Views compute canonical "turn pairs" or "problem → solution" datasets.
  4. Datasets feed into fine-tuning or eval pipelines.

Why Tongbuku 同步库?

  • One append-only history per domain instead of many bespoke data trails.
  • Views can be recomputed as model needs change.
  • Trails can be filtered based on privacy or product constraints.

Example: derived view for training

// Pseudo-code: fetch conversation_summary views for training
const res = await fetch(
  "https://tongbuku.example.com/v1/views/search?scope=conversation_summary&tag=domain:docs"
);

const { snapshots } = await res.json();
const trainingExamples = snapshots.map((snap) => ({
  input: snap.data.summary,
  meta: {
    participants: snap.data.participants,
    languages: snap.data.languages
  }
}));

4. EarthCloud + ChatCard + Tongbuku 同步库 together

A full-stack integration uses ChatCard to represent who, EarthCloud to represent what, and Tongbuku 同步库 to store how it unfolded.

Pieces

  • ChatCard token → card_id, persona, permission level.
  • EarthCloud → GlyphIR blocks and realization results.
  • Tongbuku 同步库 → trails of events tying everything together.

Trail event wiring

Each Tongbuku 同步库 event may include glyphir_id, card_id, and other IDs in its payload or actors.

// Pseudo-code: combined event payload
const event = {
  event_id: "evt_01COMBO...",
  trail_id: "trail_chat_abc",
  kind: "turn",
  timestamp: new Date().toISOString(),
  actors: {
    user_id: chatcardProfile.sub,
    card_id: chatcardProfile.card_id,
    app_id: "buoychong",
    model_id: "earthcloud_model_vX"
  },
  payload: {
    type: "glyphir_turn",
    glyphir_id: glyphirBlock.glyphir_id,
    text_in: userText,
    text_out: realizationResult.realizations[0].text,
    languages: {
      source: glyphirBlock.source_lang,
      targets: glyphirBlock.target_langs
    }
  }
};

Design patterns

Patterns that tend to work well with Tongbuku 同步库:

  • One trail per logical storyline. Conversation, session, or workflow—not per HTTP request.
  • Event payloads as deltas. Don't store full blobs if you can store small changes and views.
  • Always append, never mutate. Corrections are new events, not edits.
  • Use tags aggressively. They're your friend for analytics and dataset construction.