syntax = "proto3";

package rbt.mcp.v1;

import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";
import "rbt/v1alpha1/options.proto";

////////////////////////////////////////////////////////////////////////

message Stream {
  option (rbt.v1alpha1.state) = {
  };

  // Incoming and outgoing messages captured in order.
  // Outgoing messages are all considered "events"
  // and thus have an `event_id`.
  repeated Message messages = 1;
}

////////////////////////////////////////////////////////////////////////

service StreamMethods {
  rpc Create(google.protobuf.Empty) returns (google.protobuf.Empty) {
    option (rbt.v1alpha1.method).writer = {
    };
  }

  rpc Put(PutRequest) returns (PutResponse) {
    option (rbt.v1alpha1.method).writer = {
    };
  }

  // Replay all _outgoing_ messages, which are also considered
  // events and have an `event_id`.
  rpc Replay(ReplayRequest) returns (ReplayResponse) {
    option (rbt.v1alpha1.method).reader = {
    };
  }

  rpc Messages(google.protobuf.Empty) returns (MessagesResponse) {
    option (rbt.v1alpha1.method).reader = {
    };
  }
}

////////////////////////////////////////////////////////////////////////

message Message {
  google.protobuf.Value message = 1;

  // Implies an outgoing message!
  optional string event_id = 2;

  // This is of type `RequestId` which technically in Python
  // can be either a `str` or an `int` but in practice the
  // `related_request_id` appears to be a `str`, even though
  // request IDs appear to be `int`. *sigh*
  optional string related_request_id = 3;
}

message Event {
  string id = 1;
  google.protobuf.Value message = 2;
  // See comment in `Message` above re: using `string` here.
  optional string related_request_id = 3;
}

////////////////////////////////////////////////////////////////////////

message PutRequest {
  google.protobuf.Value message = 1;
  optional string event_id = 2;
  // See comment in `Message` above re: using `string` here.
  optional string related_request_id = 3;
}

message PutResponse {}

////////////////////////////////////////////////////////////////////////

message ReplayRequest {
  optional string last_event_id = 1;
}

message ReplayResponse {
  repeated Event events = 1;
}

////////////////////////////////////////////////////////////////////////

message MessagesResponse {
  repeated Message messages = 1;
}

////////////////////////////////////////////////////////////////////////
