// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// Genkit sample — gRPC service definition.
//
// Each RPC maps 1:1 to a Genkit flow defined in src/flows.py.
// The server implementation (src/grpc_server.py) delegates to the
// same flow functions used by the REST endpoints.
syntax = "proto3";
package genkit.sample.v1;
option java_package = "com.google.genkit.sample.v1";
option java_multiple_files = true;
// ── Request / Response messages ─────────────────────────────────────
message JokeRequest {
string name = 1; // Subject of the joke (default: "Mittens").
string username = 2; // Optional. For personalization.
}
message JokeResponse {
string joke = 1;
string username = 2;
}
message TranslateRequest {
string text = 1;
string target_language = 2; // Default: "French".
}
message TranslationResponse {
string original_text = 1;
string translated_text = 2;
string target_language = 3;
string confidence = 4;
}
message ImageRequest {
string image_url = 1; // URL of an image to describe.
}
message ImageResponse {
string description = 1;
string image_url = 2;
}
message CharacterRequest {
string name = 1; // Character name (default: "Luna").
}
message Skills {
int32 strength = 1;
int32 charisma = 2;
int32 endurance = 3;
}
message RpgCharacter {
string name = 1;
string back_story = 2;
repeated string abilities = 3;
Skills skills = 4;
}
message ChatRequest {
string question = 1;
}
message ChatResponse {
string answer = 1;
string persona = 2;
}
message StoryRequest {
string topic = 1; // Default: "a brave cat".
}
message StoryChunk {
string text = 1;
}
message StoryResponse {
string text = 1;
}
message CodeRequest {
string description = 1;
string language = 2; // Default: "python".
}
message CodeResponse {
string code = 1;
string language = 2;
string explanation = 3;
string filename = 4;
}
message CodeReviewRequest {
string code = 1;
string language = 2; // Optional — auto-detected if empty.
}
message CodeReviewResponse {
string review = 1; // JSON-encoded review output.
}
message HealthRequest {}
message HealthResponse {
string status = 1;
}
// ── Service definition ──────────────────────────────────────────────
// GenkitService exposes Genkit flows as gRPC endpoints.
//
// Every RPC is a thin wrapper around the corresponding Genkit flow,
// so traces, metrics, and the DevUI work identically whether the
// flow is called via REST or gRPC.
service GenkitService {
// Health check.
rpc Health(HealthRequest) returns (HealthResponse);
// Generate a joke.
rpc TellJoke(JokeRequest) returns (JokeResponse);
// Translate text with structured output.
rpc TranslateText(TranslateRequest) returns (TranslationResponse);
// Describe an image (multimodal).
rpc DescribeImage(ImageRequest) returns (ImageResponse);
// Generate an RPG character (structured output).
rpc GenerateCharacter(CharacterRequest) returns (RpgCharacter);
// Chat with a pirate captain persona.
rpc PirateChat(ChatRequest) returns (ChatResponse);
// Generate a story — server-side streaming.
rpc TellStory(StoryRequest) returns (stream StoryChunk);
// Generate code (structured output).
rpc GenerateCode(CodeRequest) returns (CodeResponse);
// Review code using a Dotprompt.
rpc ReviewCode(CodeReviewRequest) returns (CodeReviewResponse);
}