Skip to main content

Overview

The Orchestration API provides the core command/event architecture for T3 Code. It follows event sourcing principles where commands are dispatched, domain events are persisted, and read models are projected from the event stream.

Architecture

Available Methods

All orchestration methods use the orchestration.* namespace:
method
Retrieve the current read model snapshot
method
Execute a command (create/update/delete operations)
method
Get git diff for a specific turn range
method
Get complete diff for all turns in a thread
method
Replay events from a specific sequence number

getSnapshot

Retrieve the complete current state of all projects, threads, and sessions.

Request

Response

number
required
Current event sequence number
array
required
Array of project entities
array
required
Array of thread entities with messages, activities, and checkpoints
string
required
Last snapshot update timestamp (ISO 8601)

Example Response


dispatchCommand

Execute a command to modify system state. Commands are validated, processed, and result in domain events.

Request

ClientOrchestrationCommand
required
Command object with type discriminator

Response

number
required
Event sequence number after command processing

Available Commands

See Commands for the complete list of command types.

getTurnDiff

Retrieve the git diff for a specific range of turns within a thread.

Request

string
required
Thread identifier
number
required
Starting turn number (inclusive)
number
required
Ending turn number (inclusive). Must be ≥ fromTurnCount.

Response

string
required
Thread identifier
number
required
Starting turn number
number
required
Ending turn number
string
required
Unified diff format showing file changes

getFullThreadDiff

Retrieve the complete diff for all turns in a thread from turn 0 to the specified turn.

Request

string
required
Thread identifier
number
required
Final turn number (inclusive)

Response

Same structure as getTurnDiff, with fromTurnCount always set to 0.

replayEvents

Replay all events after a specific sequence number. Useful for rebuilding read models or catching up after reconnection.

Request

number
required
Start replaying after this sequence number (exclusive)

Response

array
required
Array of OrchestrationEvent objects in sequence order

Source Code References

Orchestration implementation:
  • Schemas: packages/contracts/src/orchestration.ts
  • Engine: apps/server/src/orchestration/Services/OrchestrationEngine.ts
  • Read Model: apps/server/src/orchestration/Services/ProjectionSnapshotQuery.ts
  • Reactor: apps/server/src/orchestration/Services/OrchestrationReactor.ts
  • WebSocket Router: apps/server/src/wsServer.ts:684-714

Domain Model

The orchestration domain is split into two aggregate roots:

Project Aggregate

Manages project metadata, workspace root, default model, and scripts

Thread Aggregate

Manages conversation threads, messages, activities, checkpoints, and provider sessions

Event Sourcing Flow

  1. Client dispatches command via dispatchCommand
  2. Server validates command against schema
  3. Command handler processes business logic
  4. Domain events are persisted to event store
  5. Read model is updated via projection
  6. Events are broadcast to all connected clients via push
  7. Client updates UI based on events

Next Steps

Commands

Explore all available command types

Events

Learn about domain event types

WebSocket Protocol

Understand the transport layer