diff --git a/pkg/server/ai_interface.go b/pkg/server/ai_interface.go new file mode 100644 index 000000000..169320cf9 --- /dev/null +++ b/pkg/server/ai_interface.go @@ -0,0 +1,58 @@ +/* +Copyright 2025 API Testing Authors. + +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. +*/ + +package server + +// AIRequest represents a standard request to an AI plugin +// Following the simplicity principle: model name + prompt + optional config +type AIRequest struct { + Model string `json:"model"` // Model identifier (e.g., "gpt-4", "claude") + Prompt string `json:"prompt"` // The prompt or instruction + Config map[string]interface{} `json:"config"` // Optional configuration (temperature, max_tokens, etc.) +} + +// AIResponse represents a standard response from an AI plugin +type AIResponse struct { + Content string `json:"content"` // The generated response + Meta map[string]interface{} `json:"meta"` // Optional metadata (model info, timing, etc.) +} + +// AICapabilities represents what an AI plugin can do +type AICapabilities struct { + Models []string `json:"models"` // Supported models + Features []string `json:"features"` // Supported features (chat, completion, etc.) + Limits map[string]int `json:"limits"` // Limits (max_tokens, rate_limit, etc.) + Description string `json:"description"` // Plugin description + Version string `json:"version"` // Plugin version +} + +// Standard AI plugin communication methods +const ( + AIMethodGenerate = "ai.generate" // Generate content from prompt + AIMethodCapabilities = "ai.capabilities" // Get plugin capabilities +) + +// Standard plugin communication message format +type PluginRequest struct { + Method string `json:"method"` // Method name + Payload interface{} `json:"payload"` // Request payload +} + +type PluginResponse struct { + Success bool `json:"success"` // Whether request succeeded + Data interface{} `json:"data"` // Response data + Error string `json:"error"` // Error message if failed +} diff --git a/pkg/server/remote_server.go b/pkg/server/remote_server.go index c88017ee1..202ab8d60 100644 --- a/pkg/server/remote_server.go +++ b/pkg/server/remote_server.go @@ -1765,3 +1765,64 @@ func (s *UniqueSlice[T]) GetAll() []T { } var errNoTestSuiteFound = errors.New("no test suite found") + +// AI Plugin Communication Methods +// These methods provide communication interface for AI plugins using the existing ExtManager + +// GetAIPlugins returns all plugins with "ai" category +func (s *server) GetAIPlugins(ctx context.Context, req *Empty) (*StoreKinds, error) { + stores, err := s.GetStoreKinds(ctx, req) + if err != nil { + return nil, err + } + + var aiPlugins []*StoreKind + for _, store := range stores.Data { + for _, category := range store.Categories { + if category == "ai" { + aiPlugins = append(aiPlugins, store) + break + } + } + } + + return &StoreKinds{Data: aiPlugins}, nil +} + +// SendAIRequest sends a request to an AI plugin using the standard plugin communication protocol +func (s *server) SendAIRequest(ctx context.Context, pluginName string, req *AIRequest) (*AIResponse, error) { + // This would communicate with the AI plugin via unix socket using PluginRequest/PluginResponse + // Implementation would be similar to other plugin communications + + // TODO: Send pluginReq to plugin via storeExtMgr communication channel + // pluginReq := &PluginRequest{ + // Method: AIMethodGenerate, + // Payload: req, + // } + + remoteServerLogger.Info("Sending AI request", "plugin", pluginName, "model", req.Model) + + return &AIResponse{ + Content: "AI response placeholder - implementation needed", + Meta: map[string]interface{}{"plugin": pluginName, "model": req.Model}, + }, nil +} + +// GetAICapabilities gets capabilities from an AI plugin +func (s *server) GetAICapabilities(ctx context.Context, pluginName string) (*AICapabilities, error) { + // TODO: Send pluginReq to plugin via storeExtMgr communication channel + // pluginReq := &PluginRequest{ + // Method: AIMethodCapabilities, + // Payload: &Empty{}, + // } + + remoteServerLogger.Info("Getting AI capabilities", "plugin", pluginName) + + return &AICapabilities{ + Models: []string{"placeholder-model"}, + Features: []string{"generate", "capabilities"}, + Limits: map[string]int{"max_tokens": 4096}, + Description: "AI plugin capabilities placeholder", + Version: "1.0.0", + }, nil +} diff --git a/pkg/testing/testdata/data/core/extension.yaml b/pkg/testing/testdata/data/core/extension.yaml index de7d5be96..4464b6abb 100644 --- a/pkg/testing/testdata/data/core/extension.yaml +++ b/pkg/testing/testdata/data/core/extension.yaml @@ -3,3 +3,8 @@ items: dependencies: - name: atest-store-database link: https://github.com/LinuxSuRen/atest-ext-store-database + - name: atest-ext-ai + dependencies: + - name: atest-ext-ai + link: https://github.com/LinuxSuRen/atest-ext-ai + categories: ["ai"]