Skip to content

Commit f10635b

Browse files
authored
feat: define AI plugin communication interface standard (#825)
* feat: add AI plugin communication interface standards --------- Signed-off-by: Zhiyuan Zhao(赵志远) <[email protected]>
1 parent ce1f79f commit f10635b

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

pkg/server/ai_interface.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package server
18+
19+
// AIRequest represents a standard request to an AI plugin
20+
// Following the simplicity principle: model name + prompt + optional config
21+
type AIRequest struct {
22+
Model string `json:"model"` // Model identifier (e.g., "gpt-4", "claude")
23+
Prompt string `json:"prompt"` // The prompt or instruction
24+
Config map[string]interface{} `json:"config"` // Optional configuration (temperature, max_tokens, etc.)
25+
}
26+
27+
// AIResponse represents a standard response from an AI plugin
28+
type AIResponse struct {
29+
Content string `json:"content"` // The generated response
30+
Meta map[string]interface{} `json:"meta"` // Optional metadata (model info, timing, etc.)
31+
}
32+
33+
// AICapabilities represents what an AI plugin can do
34+
type AICapabilities struct {
35+
Models []string `json:"models"` // Supported models
36+
Features []string `json:"features"` // Supported features (chat, completion, etc.)
37+
Limits map[string]int `json:"limits"` // Limits (max_tokens, rate_limit, etc.)
38+
Description string `json:"description"` // Plugin description
39+
Version string `json:"version"` // Plugin version
40+
}
41+
42+
// Standard AI plugin communication methods
43+
const (
44+
AIMethodGenerate = "ai.generate" // Generate content from prompt
45+
AIMethodCapabilities = "ai.capabilities" // Get plugin capabilities
46+
)
47+
48+
// Standard plugin communication message format
49+
type PluginRequest struct {
50+
Method string `json:"method"` // Method name
51+
Payload interface{} `json:"payload"` // Request payload
52+
}
53+
54+
type PluginResponse struct {
55+
Success bool `json:"success"` // Whether request succeeded
56+
Data interface{} `json:"data"` // Response data
57+
Error string `json:"error"` // Error message if failed
58+
}

pkg/server/remote_server.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,3 +1765,64 @@ func (s *UniqueSlice[T]) GetAll() []T {
17651765
}
17661766

17671767
var errNoTestSuiteFound = errors.New("no test suite found")
1768+
1769+
// AI Plugin Communication Methods
1770+
// These methods provide communication interface for AI plugins using the existing ExtManager
1771+
1772+
// GetAIPlugins returns all plugins with "ai" category
1773+
func (s *server) GetAIPlugins(ctx context.Context, req *Empty) (*StoreKinds, error) {
1774+
stores, err := s.GetStoreKinds(ctx, req)
1775+
if err != nil {
1776+
return nil, err
1777+
}
1778+
1779+
var aiPlugins []*StoreKind
1780+
for _, store := range stores.Data {
1781+
for _, category := range store.Categories {
1782+
if category == "ai" {
1783+
aiPlugins = append(aiPlugins, store)
1784+
break
1785+
}
1786+
}
1787+
}
1788+
1789+
return &StoreKinds{Data: aiPlugins}, nil
1790+
}
1791+
1792+
// SendAIRequest sends a request to an AI plugin using the standard plugin communication protocol
1793+
func (s *server) SendAIRequest(ctx context.Context, pluginName string, req *AIRequest) (*AIResponse, error) {
1794+
// This would communicate with the AI plugin via unix socket using PluginRequest/PluginResponse
1795+
// Implementation would be similar to other plugin communications
1796+
1797+
// TODO: Send pluginReq to plugin via storeExtMgr communication channel
1798+
// pluginReq := &PluginRequest{
1799+
// Method: AIMethodGenerate,
1800+
// Payload: req,
1801+
// }
1802+
1803+
remoteServerLogger.Info("Sending AI request", "plugin", pluginName, "model", req.Model)
1804+
1805+
return &AIResponse{
1806+
Content: "AI response placeholder - implementation needed",
1807+
Meta: map[string]interface{}{"plugin": pluginName, "model": req.Model},
1808+
}, nil
1809+
}
1810+
1811+
// GetAICapabilities gets capabilities from an AI plugin
1812+
func (s *server) GetAICapabilities(ctx context.Context, pluginName string) (*AICapabilities, error) {
1813+
// TODO: Send pluginReq to plugin via storeExtMgr communication channel
1814+
// pluginReq := &PluginRequest{
1815+
// Method: AIMethodCapabilities,
1816+
// Payload: &Empty{},
1817+
// }
1818+
1819+
remoteServerLogger.Info("Getting AI capabilities", "plugin", pluginName)
1820+
1821+
return &AICapabilities{
1822+
Models: []string{"placeholder-model"},
1823+
Features: []string{"generate", "capabilities"},
1824+
Limits: map[string]int{"max_tokens": 4096},
1825+
Description: "AI plugin capabilities placeholder",
1826+
Version: "1.0.0",
1827+
}, nil
1828+
}

pkg/testing/testdata/data/core/extension.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ items:
33
dependencies:
44
- name: atest-store-database
55
link: https://github.com/LinuxSuRen/atest-ext-store-database
6+
- name: atest-ext-ai
7+
dependencies:
8+
- name: atest-ext-ai
9+
link: https://github.com/LinuxSuRen/atest-ext-ai
10+
categories: ["ai"]

0 commit comments

Comments
 (0)