From b68eb35812a0b5771f4a240f5906676d3ab05e01 Mon Sep 17 00:00:00 2001 From: Akshay Shah Date: Sat, 19 Aug 2023 22:00:39 -0600 Subject: [PATCH] Mark ElizaService.Say idempotent (#126) Say is free of side effects and perfectly safe to cache, so we should mark it idempotent. This also lets us demo HTTP GETs. --- internal/gen/connectrpc/eliza/v1/eliza.pb.go | 58 +++++++++---------- .../eliza/v1/elizav1connect/eliza.connect.go | 8 ++- proto/connectrpc/eliza/v1/eliza.proto | 4 +- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/internal/gen/connectrpc/eliza/v1/eliza.pb.go b/internal/gen/connectrpc/eliza/v1/eliza.pb.go index b2b6247..0e23737 100644 --- a/internal/gen/connectrpc/eliza/v1/eliza.pb.go +++ b/internal/gen/connectrpc/eliza/v1/eliza.pb.go @@ -347,38 +347,38 @@ var file_connectrpc_eliza_v1_eliza_proto_rawDesc = []byte{ 0x6d, 0x65, 0x22, 0x2f, 0x0a, 0x11, 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6e, 0x74, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x6e, 0x74, 0x65, - 0x6e, 0x63, 0x65, 0x32, 0x99, 0x02, 0x0a, 0x0c, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x03, 0x53, 0x61, 0x79, 0x12, 0x1f, 0x2e, 0x63, 0x6f, + 0x6e, 0x63, 0x65, 0x32, 0x9c, 0x02, 0x0a, 0x0c, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x4d, 0x0a, 0x03, 0x53, 0x61, 0x79, 0x12, 0x1f, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x5d, 0x0a, 0x08, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x65, 0x12, 0x24, 0x2e, 0x63, - 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, - 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, - 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, - 0x5e, 0x0a, 0x09, 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x12, 0x25, 0x2e, 0x63, - 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, - 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, - 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x64, - 0x75, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x42, - 0xd1, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, - 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x45, 0x6c, 0x69, - 0x7a, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x63, 0x6f, 0x6e, 0x6e, 0x65, - 0x63, 0x74, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x69, - 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x6e, - 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2f, 0x76, 0x31, 0x3b, - 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x45, 0x58, 0xaa, 0x02, 0x13, - 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x6c, 0x69, 0x7a, 0x61, - 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, - 0x5c, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x6e, 0x6e, - 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x5c, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x5c, 0x56, 0x31, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x15, 0x43, 0x6f, - 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x3a, 0x3a, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x3a, - 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x76, 0x31, 0x2e, 0x53, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, + 0x90, 0x02, 0x01, 0x12, 0x5d, 0x0a, 0x08, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x65, 0x12, + 0x24, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, + 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, + 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x76, + 0x65, 0x72, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, + 0x30, 0x01, 0x12, 0x5e, 0x0a, 0x09, 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x12, + 0x25, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, + 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, + 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x30, 0x01, 0x42, 0xd1, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2e, 0x76, 0x31, 0x42, 0x0a, + 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x63, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2d, 0x67, + 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, + 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x2f, + 0x76, 0x31, 0x3b, 0x65, 0x6c, 0x69, 0x7a, 0x61, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x45, 0x58, + 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x6c, + 0x69, 0x7a, 0x61, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, + 0x72, 0x70, 0x63, 0x5c, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, + 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x5c, 0x45, 0x6c, 0x69, 0x7a, 0x61, 0x5c, + 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, + 0x15, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x72, 0x70, 0x63, 0x3a, 0x3a, 0x45, 0x6c, 0x69, + 0x7a, 0x61, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/gen/connectrpc/eliza/v1/elizav1connect/eliza.connect.go b/internal/gen/connectrpc/eliza/v1/elizav1connect/eliza.connect.go index 7c6ab37..86c048e 100644 --- a/internal/gen/connectrpc/eliza/v1/elizav1connect/eliza.connect.go +++ b/internal/gen/connectrpc/eliza/v1/elizav1connect/eliza.connect.go @@ -32,7 +32,7 @@ import ( // generated with a version of connect newer than the one compiled into your binary. You can fix the // problem by either regenerating this code with an older version of connect or updating the connect // version compiled into your binary. -const _ = connect.IsAtLeastVersion0_1_0 +const _ = connect.IsAtLeastVersion1_7_0 const ( // ElizaServiceName is the fully-qualified name of the ElizaService service. @@ -81,7 +81,8 @@ func NewElizaServiceClient(httpClient connect.HTTPClient, baseURL string, opts . say: connect.NewClient[v1.SayRequest, v1.SayResponse]( httpClient, baseURL+ElizaServiceSayProcedure, - opts..., + connect.WithIdempotency(connect.IdempotencyNoSideEffects), + connect.WithClientOptions(opts...), ), converse: connect.NewClient[v1.ConverseRequest, v1.ConverseResponse]( httpClient, @@ -140,7 +141,8 @@ func NewElizaServiceHandler(svc ElizaServiceHandler, opts ...connect.HandlerOpti elizaServiceSayHandler := connect.NewUnaryHandler( ElizaServiceSayProcedure, svc.Say, - opts..., + connect.WithIdempotency(connect.IdempotencyNoSideEffects), + connect.WithHandlerOptions(opts...), ) elizaServiceConverseHandler := connect.NewBidiStreamHandler( ElizaServiceConverseProcedure, diff --git a/proto/connectrpc/eliza/v1/eliza.proto b/proto/connectrpc/eliza/v1/eliza.proto index 4818da6..2f52d8f 100644 --- a/proto/connectrpc/eliza/v1/eliza.proto +++ b/proto/connectrpc/eliza/v1/eliza.proto @@ -24,7 +24,9 @@ package connectrpc.eliza.v1; // distributions. service ElizaService { // Say is a unary RPC. Eliza responds to the prompt with a single sentence. - rpc Say(SayRequest) returns (SayResponse) {} + rpc Say(SayRequest) returns (SayResponse) { + option idempotency_level = NO_SIDE_EFFECTS; + } // Converse is a bidirectional RPC. The caller may exchange multiple // back-and-forth messages with Eliza over a long-lived connection. Eliza // responds to each ConverseRequest with a ConverseResponse.