diff --git a/base/src/com/google/idea/blaze/base/ext/IntelliJExtManager.java b/base/src/com/google/idea/blaze/base/ext/IntelliJExtManager.java index b8f56567b39..89036b4abd3 100644 --- a/base/src/com/google/idea/blaze/base/ext/IntelliJExtManager.java +++ b/base/src/com/google/idea/blaze/base/ext/IntelliJExtManager.java @@ -64,6 +64,9 @@ public class IntelliJExtManager { */ private static final String EXPERIMENT_SERVICE_PROPERTY = "use.intellij.ext.experiments"; + private static final BoolExperiment CHATBOT = + new BoolExperiment("use.intellij.ext.chatbot", false); + public static IntelliJExtManager getInstance() { return ApplicationManager.getApplication().getService(IntelliJExtManager.class); } @@ -132,4 +135,8 @@ public boolean isKytheEnabled() { public static boolean isExperimentsServiceEnabled() { return Objects.equals(System.getProperty(EXPERIMENT_SERVICE_PROPERTY), "1"); } + + public boolean isChatBotEnabled() { + return isEnabled() && CHATBOT.getValue(); + } } diff --git a/ext/proto/BUILD b/ext/proto/BUILD index 367bf40ebe3..ced2c6b5d03 100644 --- a/ext/proto/BUILD +++ b/ext/proto/BUILD @@ -5,6 +5,7 @@ proto_library( name = "intellijext_proto", srcs = [ "build_service.proto", + "chatbotmodel.proto", "experiments.proto", "intellijext.proto", "issuetracker.proto", diff --git a/ext/proto/chatbotmodel.proto b/ext/proto/chatbotmodel.proto new file mode 100644 index 00000000000..bdb6f8c9bc2 --- /dev/null +++ b/ext/proto/chatbotmodel.proto @@ -0,0 +1,85 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * 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. + */ +syntax = "proto3"; + +package com.google.idea.blaze.ext; + +option java_package = "com.google.idea.blaze.ext"; +option java_multiple_files = true; +option java_outer_classname = "ChatBotModelProto"; + + +// Request message for [GenerateAnswers]. +message GenerateAnswersRequest { + // Specified when a message is continuing an existing session. + optional string session_id = 1; + + // Identifies which chatbot or model to query. + optional string model_id = 2; + + // Unformatted user prompt. + optional string text = 3; +} + +message GenerateAnswersResponse { + optional Message response = 1; +} + +message Timestamp { + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + optional int64 seconds = 1; + + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + optional int32 nanos = 2; +} + +// A chat message. +message Message { + // The ID of the message. + optional string message_id = 1; + + // The ID of the session. + optional string session_id = 2; + + // The unformatted contents of the message. + optional string text = 3; + + // Identifies which model the message is associated with. + optional string model_id = 4; + + optional Timestamp creation_timestamp = 5; + + repeated RelatedResources related_resources = 6; +} + +message RelatedResources { + // Identifies the origin url of the resource. + optional string url = 1; + + // Identifies the title associated with the resource. + optional string title = 2; +} + +service ChatBotModel { + // Returns GenerateAnswersResponse given GenerateAnswersRequest + rpc GenerateAnswers(GenerateAnswersRequest) + returns (GenerateAnswersResponse) {} +} diff --git a/ext/src/com/google/idea/blaze/ext/IntelliJExtClient.java b/ext/src/com/google/idea/blaze/ext/IntelliJExtClient.java index 659be3572eb..f27cd45c8f9 100644 --- a/ext/src/com/google/idea/blaze/ext/IntelliJExtClient.java +++ b/ext/src/com/google/idea/blaze/ext/IntelliJExtClient.java @@ -16,6 +16,7 @@ package com.google.idea.blaze.ext; import com.google.idea.blaze.ext.BuildServiceGrpc.BuildServiceFutureStub; +import com.google.idea.blaze.ext.ChatBotModelGrpc.ChatBotModelBlockingStub; import com.google.idea.blaze.ext.ExperimentsServiceGrpc.ExperimentsServiceBlockingStub; import com.google.idea.blaze.ext.IntelliJExtGrpc.IntelliJExtBlockingStub; import com.google.idea.blaze.ext.IssueTrackerGrpc.IssueTrackerBlockingStub; @@ -78,6 +79,10 @@ public ExperimentsServiceBlockingStub getExperimentsService() { return ExperimentsServiceGrpc.newBlockingStub(channel); } + public ChatBotModelBlockingStub getChatBotModelService() { + return ChatBotModelGrpc.newBlockingStub(channel); + } + public LinterFutureStub getLinterService() { return LinterGrpc.newFutureStub(channel); } diff --git a/ext/src/com/google/idea/blaze/ext/IntelliJExtService.java b/ext/src/com/google/idea/blaze/ext/IntelliJExtService.java index 14d19405233..ba95d70d6b1 100644 --- a/ext/src/com/google/idea/blaze/ext/IntelliJExtService.java +++ b/ext/src/com/google/idea/blaze/ext/IntelliJExtService.java @@ -17,6 +17,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.idea.blaze.ext.BuildServiceGrpc.BuildServiceFutureStub; +import com.google.idea.blaze.ext.ChatBotModelGrpc.ChatBotModelBlockingStub; import com.google.idea.blaze.ext.ExperimentsServiceGrpc.ExperimentsServiceBlockingStub; import com.google.idea.blaze.ext.IntelliJExtGrpc.IntelliJExtBlockingStub; import com.google.idea.blaze.ext.IssueTrackerGrpc.IssueTrackerBlockingStub; @@ -159,6 +160,11 @@ public ExperimentsServiceBlockingStub getExperimentsService() throws IOException return client.getExperimentsService(); } + public ChatBotModelBlockingStub getChatBotModelService() throws IOException { + IntelliJExtBlockingStub unused = connect(); + return client.getChatBotModelService(); + } + public LinterFutureStub getLinterService() throws IOException { IntelliJExtBlockingStub unused = connect(); return client.getLinterService();