From 046f0709b0643fe0551f6cf4dbb608730f4d0e8e Mon Sep 17 00:00:00 2001 From: Casey Brooks Date: Tue, 10 Mar 2026 01:22:58 +0000 Subject: [PATCH 1/2] chore(proto): switch to BSR export --- .github/workflows/ci.yml | 4 +++- .github/workflows/release.yml | 4 +++- Dockerfile | 3 ++- Makefile | 1 + .../token_counting/v1/token_counting.proto | 23 ------------------- internal/server/server.go | 2 +- internal/server/server_test.go | 8 +++---- 7 files changed, 14 insertions(+), 31 deletions(-) delete mode 100644 internal/.proto/agynio/api/token_counting/v1/token_counting.proto diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35faad0..8e86db6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,9 @@ jobs: run: echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH" - name: Generate protobuf bindings - run: buf generate internal/.proto --template ./buf.gen.yaml + run: | + buf export buf.build/agynio/api --output internal/.proto + buf generate internal/.proto --template ./buf.gen.yaml - name: Run tests run: go test ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d77c29..e2cfb0a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,7 +48,9 @@ jobs: run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" - name: Generate protobufs - run: buf generate internal/.proto --template ./buf.gen.yaml + run: | + buf export buf.build/agynio/api --output internal/.proto + buf generate internal/.proto --template ./buf.gen.yaml - name: Run tests run: go test ./... diff --git a/Dockerfile b/Dockerfile index f6fcee1..6b836a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,8 @@ RUN go mod download COPY . . -RUN buf generate internal/.proto --template ./buf.gen.yaml +RUN buf export buf.build/agynio/api --output internal/.proto && \ + buf generate internal/.proto --template ./buf.gen.yaml RUN go build -o /out/token-counting ./cmd/token-counting diff --git a/Makefile b/Makefile index 461e239..579ffb9 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ BUF_TEMPLATE := ./buf.gen.yaml all: build proto: + buf export buf.build/agynio/api --output $(PROTO_DIR) buf generate $(PROTO_DIR) --template $(BUF_TEMPLATE) build: diff --git a/internal/.proto/agynio/api/token_counting/v1/token_counting.proto b/internal/.proto/agynio/api/token_counting/v1/token_counting.proto deleted file mode 100644 index 53c9680..0000000 --- a/internal/.proto/agynio/api/token_counting/v1/token_counting.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -package agynio.api.token_counting.v1; - -option go_package = "github.com/agynio/api/gen/agynio/api/token_counting/v1;token_countingv1"; - -service TokenCountingService { - rpc CountTokens(CountTokensRequest) returns (CountTokensResponse); -} - -enum Model { - MODEL_UNSPECIFIED = 0; - MODEL_GPT_5 = 1; -} - -message CountTokensRequest { - Model model = 1; - repeated bytes messages = 2; -} - -message CountTokensResponse { - repeated int32 tokens = 1; -} diff --git a/internal/server/server.go b/internal/server/server.go index 3776c35..02d921f 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -75,7 +75,7 @@ func validateCountTokensRequest(req *tokencountingv1.CountTokensRequest) error { if req == nil { return status.Error(codes.InvalidArgument, "request required") } - if req.GetModel() == tokencountingv1.Model_MODEL_UNSPECIFIED { + if req.GetModel() == tokencountingv1.TokenCountingModel_TOKEN_COUNTING_MODEL_UNSPECIFIED { return status.Error(codes.InvalidArgument, "model is required") } if len(req.GetMessages()) == 0 { diff --git a/internal/server/server_test.go b/internal/server/server_test.go index bd0671b..515596d 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -33,7 +33,7 @@ func TestCountTokensSuccess(t *testing.T) { expectedB := countTokens(t, tokenizerInstance, messageB) resp, err := client.CountTokens(context.Background(), &tokencountingv1.CountTokensRequest{ - Model: tokencountingv1.Model_MODEL_GPT_5, + Model: tokencountingv1.TokenCountingModel_TOKEN_COUNTING_MODEL_GPT_5, Messages: [][]byte{messageA, messageB}, }) if err != nil { @@ -69,7 +69,7 @@ func TestCountTokensEmptyMessages(t *testing.T) { defer cleanup() _, err := client.CountTokens(context.Background(), &tokencountingv1.CountTokensRequest{ - Model: tokencountingv1.Model_MODEL_GPT_5, + Model: tokencountingv1.TokenCountingModel_TOKEN_COUNTING_MODEL_GPT_5, }) if err == nil { t.Fatal("expected error, got nil") @@ -83,7 +83,7 @@ func TestCountTokensInvalidArgumentMapping(t *testing.T) { defer cleanup() _, err := client.CountTokens(context.Background(), &tokencountingv1.CountTokensRequest{ - Model: tokencountingv1.Model_MODEL_GPT_5, + Model: tokencountingv1.TokenCountingModel_TOKEN_COUNTING_MODEL_GPT_5, Messages: [][]byte{[]byte("{}")}, }) if err == nil { @@ -99,7 +99,7 @@ func TestCountTokensInternalErrorMapping(t *testing.T) { defer cleanup() _, err := client.CountTokens(context.Background(), &tokencountingv1.CountTokensRequest{ - Model: tokencountingv1.Model_MODEL_GPT_5, + Model: tokencountingv1.TokenCountingModel_TOKEN_COUNTING_MODEL_GPT_5, Messages: [][]byte{[]byte("{}")}, }) if err == nil { From 390879c803ef3955f929e308177345160d244af5 Mon Sep 17 00:00:00 2001 From: Casey Brooks Date: Tue, 10 Mar 2026 01:32:04 +0000 Subject: [PATCH 2/2] chore(gitignore): ignore exported protos --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f9fa863..1ca5f21 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ dist/ # Generated code internal/.gen/ + +# Exported protos internal/.proto/ # Editor