灵隙(synapse) v1.0.0 版本

This commit is contained in:
lychang
2026-06-28 03:24:26 +08:00
parent 88b606b9ca
commit 812f68d5aa
48 changed files with 5566 additions and 1499 deletions

View File

@@ -0,0 +1,706 @@
package grpcapi
import (
"context"
"fmt"
"io"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
)
// =============================================================================
// gRPC Client SDK for Synapse Protocol
// =============================================================================
// GRPCClient is a high-level client for Synapse gRPC services
type GRPCClient struct {
conn *grpc.ClientConn
taskClient TaskServiceClient
messageClient A2AMessageServiceClient
capsClient CapabilitiesServiceClient
groupClient GroupServiceClient
healthClient HealthServiceClient
// Configuration
apiKey string
timeout time.Duration
}
// GRPCClientConfig client configuration
type GRPCClientConfig struct {
Address string
APIKey string
Timeout time.Duration
Insecure bool // For development only
}
// NewGRPCClient creates a new gRPC client
func NewGRPCClient(config GRPCClientConfig) (*GRPCClient, error) {
if config.Timeout == 0 {
config.Timeout = 30 * time.Second
}
var opts []grpc.DialOption
if config.Insecure {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
// Add interceptor for API key
opts = append(opts, grpc.WithUnaryInterceptor(apiKeyInterceptor(config.APIKey)))
opts = append(opts, grpc.WithStreamInterceptor(apiKeyStreamInterceptor(config.APIKey)))
ctx, cancel := context.WithTimeout(context.Background(), config.Timeout)
defer cancel()
conn, err := grpc.DialContext(ctx, config.Address, opts...)
if err != nil {
return nil, fmt.Errorf("failed to connect: %w", err)
}
return &GRPCClient{
conn: conn,
taskClient: NewTaskServiceClient(conn),
messageClient: NewA2AMessageServiceClient(conn),
capsClient: NewCapabilitiesServiceClient(conn),
groupClient: NewGroupServiceClient(conn),
healthClient: NewHealthServiceClient(conn),
apiKey: config.APIKey,
timeout: config.Timeout,
}, nil
}
// Close closes the client connection
func (c *GRPCClient) Close() error {
return c.conn.Close()
}
// =============================================================================
// Interceptors
// =============================================================================
func apiKeyInterceptor(apiKey string) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
if apiKey != "" {
ctx = metadata.AppendToOutgoingContext(ctx, "x-api-key", apiKey)
}
return invoker(ctx, method, req, reply, cc, opts...)
}
}
func apiKeyStreamInterceptor(apiKey string) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
if apiKey != "" {
ctx = metadata.AppendToOutgoingContext(ctx, "x-api-key", apiKey)
}
return streamer(ctx, desc, cc, method, opts...)
}
}
// =============================================================================
// Task Operations
// =============================================================================
// SubmitTask submits a new task
func (c *GRPCClient) SubmitTask(ctx context.Context, taskType string, payload map[string]any, opts ...TaskOption) (*SubmitTaskResponse, error) {
req := &SubmitTaskRequest{
TaskType: taskType,
Priority: "normal",
}
// Apply options
for _, opt := range opts {
opt(req)
}
// Convert payload to Any
if payload != nil {
// In real implementation, use protojson.Marshal
req.Payload = &anypb.Any{
Value: []byte(fmt.Sprintf("%v", payload)),
}
}
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.taskClient.SubmitTask(ctx, req)
}
// TaskOption configures task submission
type TaskOption func(*SubmitTaskRequest)
func WithExternalTaskID(id string) TaskOption {
return func(r *SubmitTaskRequest) {
r.ExternalTaskId = id
}
}
func WithPriority(priority string) TaskOption {
return func(r *SubmitTaskRequest) {
r.Priority = priority
}
}
func WithCallback(url, token string) TaskOption {
return func(r *SubmitTaskRequest) {
r.CallbackUrl = url
r.CallbackToken = token
}
}
func WithTransportMode(mode TransportMode) TaskOption {
return func(r *SubmitTaskRequest) {
r.PreferredTransport = mode
}
}
// GetTask gets task details
func (c *GRPCClient) GetTask(ctx context.Context, taskID string) (*TaskInfo, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.taskClient.GetTask(ctx, &GetTaskRequest{TaskId: taskID})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("task query failed: %s", resp.ErrorMessage)
}
return resp.Task, nil
}
// GetTaskStatus gets simplified task status
func (c *GRPCClient) GetTaskStatus(ctx context.Context, taskID string) (*TaskInfo, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.taskClient.GetTaskStatus(ctx, &GetTaskRequest{TaskId: taskID})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("status query failed: %s", resp.ErrorMessage)
}
return resp.Task, nil
}
// ListTasks lists tasks with filtering
func (c *GRPCClient) ListTasks(ctx context.Context, status string, limit, offset int) (*ListTasksResponse, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.taskClient.ListTasks(ctx, &ListTasksRequest{
Status: status,
Limit: int32(limit),
Offset: int32(offset),
})
}
// CancelTask cancels a task
func (c *GRPCClient) CancelTask(ctx context.Context, taskID string) (*CancelTaskResponse, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.taskClient.CancelTask(ctx, &CancelTaskRequest{TaskId: taskID})
}
// =============================================================================
// Streaming Operations
// =============================================================================
// StreamTaskStatus streams task status updates
func (c *GRPCClient) StreamTaskStatus(ctx context.Context, taskID string) (<-chan *TaskStatusUpdate, error) {
stream, err := c.taskClient.StreamTaskStatus(ctx)
if err != nil {
return nil, fmt.Errorf("failed to start stream: %w", err)
}
// Send subscription request
if err := stream.Send(&TaskStatusStreamRequest{
TaskId: taskID,
Subscribe: true,
}); err != nil {
return nil, fmt.Errorf("failed to subscribe: %w", err)
}
updateChan := make(chan *TaskStatusUpdate, 100)
go func() {
defer close(updateChan)
for {
update, err := stream.Recv()
if err == io.EOF {
return
}
if err != nil {
log.Printf("[gRPC Stream] Receive error: %v", err)
return
}
updateChan <- update
}
}()
return updateChan, nil
}
// StreamMessages opens a bidirectional message stream
func (c *GRPCClient) StreamMessages(ctx context.Context) (chan<- *A2AMessage, <-chan *A2AMessage, error) {
stream, err := c.messageClient.StreamMessages(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to start message stream: %w", err)
}
sendChan := make(chan *A2AMessage, 100)
recvChan := make(chan *A2AMessage, 100)
// Send goroutine
go func() {
for msg := range sendChan {
if err := stream.Send(msg); err != nil {
log.Printf("[gRPC Stream] Send error: %v", err)
return
}
}
}()
// Receive goroutine
go func() {
defer close(recvChan)
for {
msg, err := stream.Recv()
if err == io.EOF {
return
}
if err != nil {
log.Printf("[gRPC Stream] Receive error: %v", err)
return
}
recvChan <- msg
}
}()
return sendChan, recvChan, nil
}
// =============================================================================
// Message Operations
// =============================================================================
// SendMessage sends a single Synapse message
func (c *GRPCClient) SendMessage(ctx context.Context, msg *A2AMessage) (*SendMessageResponse, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.messageClient.SendMessage(ctx, &SendMessageRequest{Message: msg})
}
// =============================================================================
// Capabilities Operations
// =============================================================================
// GetCapabilities gets agent capabilities
func (c *GRPCClient) GetCapabilities(ctx context.Context) (*AgentCapabilities, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.capsClient.GetCapabilities(ctx, &emptypb.Empty{})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("capabilities query failed: %s", resp.Error)
}
return resp.Capabilities, nil
}
// ListAgents lists available agents
func (c *GRPCClient) ListAgents(ctx context.Context) ([]*AgentInfo, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.capsClient.ListAgents(ctx, &emptypb.Empty{})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("agent list failed")
}
return resp.Agents, nil
}
// =============================================================================
// Group Operations
// =============================================================================
// CreateGroup creates a new group
func (c *GRPCClient) CreateGroup(ctx context.Context, name, description, coordinatorID string, initialMembers []string) (*GroupInfo, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.CreateGroup(ctx, &CreateGroupRequest{
Name: name,
Description: description,
CoordinatorId: coordinatorID,
InitialMembers: initialMembers,
})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("group creation failed: %s", resp.Error)
}
return resp.Group, nil
}
// JoinGroup joins an existing group
func (c *GRPCClient) JoinGroup(ctx context.Context, groupID string, agent *AgentEndpoint) error {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.JoinGroup(ctx, &JoinGroupRequest{
GroupId: groupID,
Agent: agent,
})
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("join failed: %s", resp.Error)
}
return nil
}
// LeaveGroup leaves a group
func (c *GRPCClient) LeaveGroup(ctx context.Context, groupID, agentID string) error {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.LeaveGroup(ctx, &LeaveGroupRequest{
GroupId: groupID,
AgentId: agentID,
})
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("leave failed: %s", resp.Error)
}
return nil
}
// ListGroupMembers lists group members
func (c *GRPCClient) ListGroupMembers(ctx context.Context, groupID string) ([]*GroupMember, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.ListGroupMembers(ctx, &ListGroupMembersRequest{GroupId: groupID})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("member list failed")
}
return resp.Members, nil
}
// =============================================================================
// Voting Operations (Group Protocol)
// =============================================================================
// InitiateVote initiates a vote in a group
func (c *GRPCClient) InitiateVote(ctx context.Context, groupID, initiatorID, question string, options []string, threshold float64, timeoutSeconds int32) (string, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.InitiateVote(ctx, &VoteRequest{
GroupId: groupID,
InitiatorId: initiatorID,
Question: question,
Options: options,
Threshold: threshold,
TimeoutSeconds: timeoutSeconds,
})
if err != nil {
return "", err
}
if !resp.Success {
return "", fmt.Errorf("initiate vote failed: %s", resp.Error)
}
return resp.VoteId, nil
}
// SubmitVote submits a vote
func (c *GRPCClient) SubmitVote(ctx context.Context, voteID, agentID, option, reason string) error {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.SubmitVote(ctx, &SubmitVoteRequest{
VoteId: voteID,
AgentId: agentID,
Option: option,
Reason: reason,
})
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("submit vote failed: %s", resp.Error)
}
return nil
}
// GetVoteStatus gets the current status of a vote
func (c *GRPCClient) GetVoteStatus(ctx context.Context, voteID string) (*VoteStatusResponse, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.groupClient.GetVoteStatus(ctx, &GetVoteStatusRequest{VoteId: voteID})
}
// WaitForVote waits for a vote to complete
func (c *GRPCClient) WaitForVote(ctx context.Context, voteID string, interval time.Duration) (*VoteStatusResponse, error) {
if interval == 0 {
interval = 2 * time.Second
}
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ticker.C:
status, err := c.GetVoteStatus(ctx, voteID)
if err != nil {
continue
}
if status.Status == "decided" || status.Status == "expired" {
return status, nil
}
}
}
}
// =============================================================================
// Task Split & Merge Operations (Group Protocol)
// =============================================================================
// SplitTask splits a task into subtasks
func (c *GRPCClient) SplitTask(ctx context.Context, groupID, taskID, taskType, requirements string, strategy SplitStrategy) ([]*SubtaskInfo, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.groupClient.SplitTask(ctx, &SplitTaskRequest{
GroupId: groupID,
TaskId: taskID,
TaskType: taskType,
Requirements: requirements,
Strategy: strategy,
})
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("split task failed: %s", resp.Error)
}
return resp.Subtasks, nil
}
// MergeResults merges subtask results
func (c *GRPCClient) MergeResults(ctx context.Context, groupID, parentTaskID string, strategy MergeStrategy) (*MergeResultsResponse, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.groupClient.MergeResults(ctx, &MergeResultsRequest{
GroupId: groupID,
ParentTaskId: parentTaskID,
Strategy: strategy,
})
}
// =============================================================================
// Health Operations
// =============================================================================
// HealthCheck checks server health
func (c *GRPCClient) HealthCheck(ctx context.Context) (*HealthCheckResponse, error) {
ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
return c.healthClient.HealthCheck(ctx, &emptypb.Empty{})
}
// =============================================================================
// High-Level Helpers
// =============================================================================
// CreateAndWait creates a task and waits for completion via streaming
func (c *GRPCClient) CreateAndWait(ctx context.Context, taskType string, payload map[string]any, timeout time.Duration) (*TaskInfo, error) {
// Submit task
resp, err := c.SubmitTask(ctx, taskType, payload)
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("task submission failed: %s", resp.Message)
}
// Stream status until completion
updateChan, err := c.StreamTaskStatus(ctx, resp.TaskId)
if err != nil {
return nil, err
}
// Wait with timeout
if timeout == 0 {
timeout = 5 * time.Minute
}
timer := time.NewTimer(timeout)
defer timer.Stop()
for {
select {
case update := <-updateChan:
if update == nil {
return nil, fmt.Errorf("stream closed unexpectedly")
}
switch update.Status {
case TaskStatus_TASK_STATUS_COMPLETED:
return &TaskInfo{
Id: resp.TaskId,
Status: update.Status,
Progress: update.Progress,
Message: update.Message,
}, nil
case TaskStatus_TASK_STATUS_FAILED, TaskStatus_TASK_STATUS_CANCELLED:
return nil, fmt.Errorf("task failed: %s", update.Message)
}
case <-timer.C:
return nil, fmt.Errorf("timeout waiting for task completion")
case <-ctx.Done():
return nil, ctx.Err()
}
}
}
// WaitForTask waits for a task to complete using polling
func (c *GRPCClient) WaitForTask(ctx context.Context, taskID string, interval time.Duration) (*TaskInfo, error) {
if interval == 0 {
interval = 5 * time.Second
}
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ticker.C:
task, err := c.GetTaskStatus(ctx, taskID)
if err != nil {
continue
}
switch task.Status {
case TaskStatus_TASK_STATUS_COMPLETED:
return task, nil
case TaskStatus_TASK_STATUS_FAILED, TaskStatus_TASK_STATUS_CANCELLED:
return task, fmt.Errorf("task failed: %s", task.Message)
}
}
}
}
// =============================================================================
// Builder Pattern for A2AMessage
// =============================================================================
// MessageBuilder builds Synapse messages
type MessageBuilder struct {
msg *A2AMessage
}
// NewMessage creates a new message builder
func NewMessage() *MessageBuilder {
return &MessageBuilder{
msg: &A2AMessage{
Id: generateMessageID(),
Version: "1.0.0",
Timestamp: timestamppb.Now(),
},
}
}
func (b *MessageBuilder) Type(msgType MessageType) *MessageBuilder {
b.msg.Type = msgType
return b
}
func (b *MessageBuilder) From(sender *AgentEndpoint) *MessageBuilder {
b.msg.Sender = sender
return b
}
func (b *MessageBuilder) To(receiver *AgentEndpoint) *MessageBuilder {
b.msg.Receiver = receiver
return b
}
func (b *MessageBuilder) CorrelationID(id string) *MessageBuilder {
b.msg.CorrelationId = id
return b
}
func (b *MessageBuilder) GroupID(id string) *MessageBuilder {
b.msg.GroupId = id
return b
}
func (b *MessageBuilder) Payload(payload []byte) *MessageBuilder {
b.msg.Payload = &anypb.Any{Value: payload}
return b
}
func (b *MessageBuilder) Build() *A2AMessage {
return b.msg
}
func generateMessageID() string {
return fmt.Sprintf("msg-%d", time.Now().UnixNano())
}

View File

@@ -0,0 +1,861 @@
package grpcapi
import (
"context"
"fmt"
"io"
"log"
"net"
"net/http"
"sync"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
"synapse/pkg/types"
)
// =============================================================================
// gRPC Server Implementation
// =============================================================================
// GRPCServer wraps the gRPC server and gateway
type GRPCServer struct {
grpcServer *grpc.Server
gateway *http.Server
mu sync.RWMutex
// Services
taskService *TaskServiceImpl
messageService *MessageServiceImpl
capabilitiesService *CapabilitiesServiceImpl
groupService *GroupServiceImpl
healthService *HealthServiceImpl
// Dependencies
taskExecutor TaskExecutor
msgRouter MessageRouter
capsProvider CapabilitiesProvider
groupManager GroupManager
}
// TaskExecutor interface for task operations
type TaskExecutor interface {
SubmitTask(ctx context.Context, taskType string, payload map[string]any, externalTaskID, priority, callbackURL, callbackToken string) (string, string, error)
GetTaskStatus(ctx context.Context, taskID string) (*types.TaskInfo, error)
ListTasks(ctx context.Context, status string, limit, offset int) ([]types.TaskInfo, int, error)
CancelTask(ctx context.Context, taskID string) error
}
type MessageRouter interface {
RouteMessage(ctx context.Context, msg *types.UnifiedSynapseMessage) (*types.UnifiedSynapseMessage, error)
}
type CapabilitiesProvider interface {
GetCapabilities(ctx context.Context) (*types.AgentCapabilities, error)
}
type GroupManager interface {
CreateGroup(ctx context.Context, name, description, coordinatorID string, initialMembers []string) (string, error)
JoinGroup(ctx context.Context, groupID string, agent *types.AgentEndpoint) error
LeaveGroup(ctx context.Context, groupID, agentID string) error
DisbandGroup(ctx context.Context, groupID string) error
ListMembers(ctx context.Context, groupID string) ([]types.GroupMember, error)
// Voting operations
InitiateVote(ctx context.Context, groupID, initiatorID, question string, options []string, threshold float64, timeoutSeconds int32) (string, error)
SubmitVote(ctx context.Context, voteID, agentID, option, reason string) error
GetVoteStatus(ctx context.Context, voteID string) (*VoteStatus, error)
// Task split and merge
SplitTask(ctx context.Context, groupID, taskID, taskType, requirements string, strategy SplitStrategy) ([]*SubtaskInfo, error)
MergeResults(ctx context.Context, groupID, parentTaskID string, strategy MergeStrategy) (*anypb.Any, string, error)
}
// VoteStatus represents the status of a vote
type VoteStatus struct {
VoteID string
Status string // open, decided, expired
Question string
TotalVotes int
RequiredVotes int
WinningOption string
Votes map[string]string // agentID -> option
}
// =============================================================================
// Server Constructor
// =============================================================================
// NewGRPCServer creates a new gRPC server
func NewGRPCServer(taskExec TaskExecutor, msgRouter MessageRouter, capsProvider CapabilitiesProvider, groupManager GroupManager) *GRPCServer {
return &GRPCServer{
taskExecutor: taskExec,
msgRouter: msgRouter,
capsProvider: capsProvider,
groupManager: groupManager,
taskService: &TaskServiceImpl{},
messageService: &MessageServiceImpl{},
capabilitiesService: &CapabilitiesServiceImpl{},
groupService: &GroupServiceImpl{},
healthService: &HealthServiceImpl{},
}
}
// Start starts both gRPC and gateway servers
func (s *GRPCServer) Start(grpcPort, gatewayPort int) error {
// Start gRPC server
go func() {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", grpcPort))
if err != nil {
log.Fatalf("[gRPC] Failed to listen: %v", err)
}
// Create gRPC server with interceptors
opts := []grpc.ServerOption{
grpc.UnaryInterceptor(s.unaryInterceptor),
grpc.StreamInterceptor(s.streamInterceptor),
}
s.grpcServer = grpc.NewServer(opts...)
// Register services
// Note: These would be generated from proto
// RegisterTaskServiceServer(s.grpcServer, s.taskService)
// RegisterA2AMessageServiceServer(s.grpcServer, s.messageService)
// ... etc
log.Printf("[gRPC] Server started on port %d", grpcPort)
if err := s.grpcServer.Serve(lis); err != nil {
log.Fatalf("[gRPC] Failed to serve: %v", err)
}
}()
// Start gRPC-Gateway
go func() {
_ = context.Background() // ctx reserved for future gateway handler registration
mux := http.NewServeMux()
// Register gateway handlers
// Note: These would be generated from proto by grpc-gateway
// err := RegisterTaskServiceHandlerFromEndpoint(ctx, mux, fmt.Sprintf("localhost:%d", grpcPort), opts)
// ... etc
s.gateway = &http.Server{
Addr: fmt.Sprintf(":%d", gatewayPort),
Handler: mux,
}
log.Printf("[Gateway] HTTP server started on port %d", gatewayPort)
if err := s.gateway.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("[Gateway] Failed to serve: %v", err)
}
}()
return nil
}
// Stop gracefully stops both servers
func (s *GRPCServer) Stop() {
if s.grpcServer != nil {
s.grpcServer.GracefulStop()
}
if s.gateway != nil {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
s.gateway.Shutdown(ctx)
}
}
// =============================================================================
// Interceptors
// =============================================================================
func (s *GRPCServer) unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
// Extract metadata
md, ok := metadata.FromIncomingContext(ctx)
if ok {
// Check API key
apiKeys := md.Get("x-api-key")
if len(apiKeys) > 0 {
// Validate API key
log.Printf("[gRPC] API Key: %s", apiKeys[0])
}
}
// Call handler
return handler(ctx, req)
}
func (s *GRPCServer) streamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
// Extract metadata
md, ok := metadata.FromIncomingContext(ss.Context())
if ok {
apiKeys := md.Get("x-api-key")
if len(apiKeys) > 0 {
log.Printf("[gRPC Stream] API Key: %s", apiKeys[0])
}
}
return handler(srv, ss)
}
// =============================================================================
// Task Service Implementation
// =============================================================================
type TaskServiceImpl struct {
UnimplementedTaskServiceServer
taskExecutor TaskExecutor
mu sync.RWMutex
streamClients map[string]chan *TaskStatusUpdate
}
func (s *TaskServiceImpl) SubmitTask(ctx context.Context, req *SubmitTaskRequest) (*SubmitTaskResponse, error) {
// Convert payload
payload := make(map[string]any)
if req.Payload != nil {
// Unpack Any to map
// This would use protojson or similar
}
taskID, status, err := s.taskExecutor.SubmitTask(
ctx,
req.TaskType,
payload,
req.ExternalTaskId,
req.Priority,
req.CallbackUrl,
req.CallbackToken,
)
if err != nil {
return &SubmitTaskResponse{
Success: false,
ErrorCode: "TASK_SUBMISSION_FAILED",
Message: err.Error(),
}, nil
}
return &SubmitTaskResponse{
Success: true,
TaskId: taskID,
Status: parseTaskStatus(status),
Message: "任务已接收",
}, nil
}
func (s *TaskServiceImpl) SubmitTaskWithFiles(ctx context.Context, req *SubmitTaskWithFilesRequest) (*SubmitTaskResponse, error) {
// Handle file uploads
// Convert files and call SubmitTask
return s.SubmitTask(ctx, req.Request)
}
func (s *TaskServiceImpl) GetTask(ctx context.Context, req *GetTaskRequest) (*TaskStatusResponse, error) {
task, err := s.taskExecutor.GetTaskStatus(ctx, req.TaskId)
if err != nil {
return &TaskStatusResponse{
Success: false,
ErrorCode: "TASK_NOT_FOUND",
ErrorMessage: err.Error(),
}, nil
}
return &TaskStatusResponse{
Success: true,
Task: convertTaskInfo(task),
}, nil
}
func (s *TaskServiceImpl) GetTaskStatus(ctx context.Context, req *GetTaskRequest) (*TaskStatusResponse, error) {
return s.GetTask(ctx, req)
}
func (s *TaskServiceImpl) ListTasks(ctx context.Context, req *ListTasksRequest) (*ListTasksResponse, error) {
tasks, total, err := s.taskExecutor.ListTasks(ctx, req.Status, int(req.Limit), int(req.Offset))
if err != nil {
return &ListTasksResponse{
Success: false,
}, err
}
var protoTasks []*TaskInfo
for _, t := range tasks {
protoTasks = append(protoTasks, convertTaskInfo(&t))
}
return &ListTasksResponse{
Success: true,
Tasks: protoTasks,
Total: int32(total),
Limit: req.Limit,
Offset: req.Offset,
HasMore: int(req.Offset+req.Limit) < total,
}, nil
}
func (s *TaskServiceImpl) CancelTask(ctx context.Context, req *CancelTaskRequest) (*CancelTaskResponse, error) {
if err := s.taskExecutor.CancelTask(ctx, req.TaskId); err != nil {
return &CancelTaskResponse{
Success: false,
Message: err.Error(),
}, nil
}
return &CancelTaskResponse{
Success: true,
TaskId: req.TaskId,
Status: TaskStatus_TASK_STATUS_CANCELLED,
Message: "任务已取消",
}, nil
}
// StreamTaskStatus implements bidirectional streaming for task status updates
func (s *TaskServiceImpl) StreamTaskStatus(stream TaskService_StreamTaskStatusServer) error {
// Register client
clientID := fmt.Sprintf("stream-%d", time.Now().UnixNano())
statusChan := make(chan *TaskStatusUpdate, 100)
s.mu.Lock()
s.streamClients[clientID] = statusChan
s.mu.Unlock()
defer func() {
s.mu.Lock()
delete(s.streamClients, clientID)
s.mu.Unlock()
close(statusChan)
}()
// Goroutine to send status updates
go func() {
for update := range statusChan {
if err := stream.Send(update); err != nil {
log.Printf("[gRPC Stream] Send error: %v", err)
return
}
}
}()
// Receive subscription requests
for {
req, err := stream.Recv()
if err == io.EOF {
return nil
}
if err != nil {
return err
}
if req.Subscribe {
log.Printf("[gRPC Stream] Client %s subscribed to task %s", clientID, req.TaskId)
// Start watching task status
go s.watchTaskStatus(req.TaskId, statusChan)
} else {
log.Printf("[gRPC Stream] Client %s unsubscribed from task %s", clientID, req.TaskId)
}
}
}
func (s *TaskServiceImpl) watchTaskStatus(taskID string, ch chan *TaskStatusUpdate) {
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
for range ticker.C {
task, err := s.taskExecutor.GetTaskStatus(context.Background(), taskID)
if err != nil {
continue
}
ch <- &TaskStatusUpdate{
TaskId: taskID,
Status: parseTaskStatus(task.Status),
Progress: int32(task.Progress),
Message: task.Message,
}
// Stop if terminal state
if task.Status == "completed" || task.Status == "failed" || task.Status == "cancelled" {
return
}
}
}
// =============================================================================
// Message Service Implementation
// =============================================================================
type MessageServiceImpl struct {
UnimplementedA2AMessageServiceServer
msgRouter MessageRouter
}
func (s *MessageServiceImpl) SendMessage(ctx context.Context, req *SendMessageRequest) (*SendMessageResponse, error) {
// Convert proto message to internal format
msg := convertProtoToInternalMessage(req.Message)
resp, err := s.msgRouter.RouteMessage(ctx, msg)
if err != nil {
return &SendMessageResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &SendMessageResponse{
Success: true,
MessageId: resp.ID,
}, nil
}
// StreamMessages implements bidirectional streaming for Synapse messages
func (s *MessageServiceImpl) StreamMessages(stream A2AMessageService_StreamMessagesServer) error {
ctx := stream.Context()
clientID := fmt.Sprintf("msg-stream-%d", time.Now().UnixNano())
log.Printf("[gRPC Stream] New message stream: %s", clientID)
// Goroutine to receive messages
go func() {
for {
msg, err := stream.Recv()
if err == io.EOF {
return
}
if err != nil {
log.Printf("[gRPC Stream] Receive error: %v", err)
return
}
internalMsg := convertProtoToInternalMessage(msg)
resp, err := s.msgRouter.RouteMessage(ctx, internalMsg)
if err != nil {
log.Printf("[gRPC Stream] Route error: %v", err)
continue
}
protoResp := convertInternalToProtoMessage(resp)
if err := stream.Send(protoResp); err != nil {
log.Printf("[gRPC Stream] Send error: %v", err)
return
}
}
}()
// Keep stream alive
<-ctx.Done()
log.Printf("[gRPC Stream] Message stream closed: %s", clientID)
return nil
}
func (s *MessageServiceImpl) ReceiveCallback(req *emptypb.Empty, stream A2AMessageService_ReceiveCallbackServer) error {
// This would be used by agents to receive callback messages via gRPC stream
// Implementation depends on callback routing mechanism
return status.Error(codes.Unimplemented, "not implemented")
}
// =============================================================================
// Capabilities Service Implementation
// =============================================================================
type CapabilitiesServiceImpl struct {
UnimplementedCapabilitiesServiceServer
provider CapabilitiesProvider
}
func (s *CapabilitiesServiceImpl) GetCapabilities(ctx context.Context, req *emptypb.Empty) (*CapabilitiesResponse, error) {
caps, err := s.provider.GetCapabilities(ctx)
if err != nil {
return &CapabilitiesResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &CapabilitiesResponse{
Success: true,
Capabilities: convertAgentCapabilities(caps),
}, nil
}
func (s *CapabilitiesServiceImpl) QueryAgent(ctx context.Context, req *QueryAgentRequest) (*CapabilitiesResponse, error) {
// Query specific agent's capabilities
return s.GetCapabilities(ctx, nil)
}
func (s *CapabilitiesServiceImpl) ListAgents(ctx context.Context, req *emptypb.Empty) (*ListAgentsResponse, error) {
return &ListAgentsResponse{
Success: true,
Agents: []*AgentInfo{},
}, nil
}
// =============================================================================
// Group Service Implementation
// =============================================================================
type GroupServiceImpl struct {
UnimplementedGroupServiceServer
groupManager GroupManager
}
func (s *GroupServiceImpl) CreateGroup(ctx context.Context, req *CreateGroupRequest) (*CreateGroupResponse, error) {
groupID, err := s.groupManager.CreateGroup(ctx, req.Name, req.Description, req.CoordinatorId, req.InitialMembers)
if err != nil {
return &CreateGroupResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &CreateGroupResponse{
Success: true,
GroupId: groupID,
Group: &GroupInfo{
Id: groupID,
Name: req.Name,
Description: req.Description,
CoordinatorId: req.CoordinatorId,
Status: "active",
CreatedAt: timestamppb.Now(),
},
}, nil
}
func (s *GroupServiceImpl) JoinGroup(ctx context.Context, req *JoinGroupRequest) (*JoinGroupResponse, error) {
err := s.groupManager.JoinGroup(ctx, req.GroupId, convertProtoEndpoint(req.Agent))
if err != nil {
return &JoinGroupResponse{Success: false, Error: err.Error()}, nil
}
return &JoinGroupResponse{Success: true}, nil
}
func (s *GroupServiceImpl) LeaveGroup(ctx context.Context, req *LeaveGroupRequest) (*LeaveGroupResponse, error) {
err := s.groupManager.LeaveGroup(ctx, req.GroupId, req.AgentId)
if err != nil {
return &LeaveGroupResponse{Success: false, Error: err.Error()}, nil
}
return &LeaveGroupResponse{Success: true}, nil
}
func (s *GroupServiceImpl) DisbandGroup(ctx context.Context, req *DisbandGroupRequest) (*DisbandGroupResponse, error) {
err := s.groupManager.DisbandGroup(ctx, req.GroupId)
if err != nil {
return &DisbandGroupResponse{Success: false, Error: err.Error()}, nil
}
return &DisbandGroupResponse{Success: true}, nil
}
func (s *GroupServiceImpl) ListGroupMembers(ctx context.Context, req *ListGroupMembersRequest) (*ListGroupMembersResponse, error) {
members, err := s.groupManager.ListMembers(ctx, req.GroupId)
if err != nil {
return &ListGroupMembersResponse{Success: false}, nil
}
var protoMembers []*GroupMember
for _, m := range members {
protoMembers = append(protoMembers, &GroupMember{
AgentId: m.AgentID,
AgentName: m.AgentName,
Role: m.Role,
Status: string(m.Status),
JoinedAt: timestamppb.Now(),
})
}
return &ListGroupMembersResponse{
Success: true,
Members: protoMembers,
}, nil
}
// StreamGroupMessages implements bidirectional streaming for group messages
func (s *GroupServiceImpl) StreamGroupMessages(stream GroupService_StreamGroupMessagesServer) error {
ctx := stream.Context()
clientID := fmt.Sprintf("group-stream-%d", time.Now().UnixNano())
log.Printf("[gRPC Stream] New group stream: %s", clientID)
go func() {
for {
msg, err := stream.Recv()
if err == io.EOF {
return
}
if err != nil {
log.Printf("[gRPC Stream] Receive error: %v", err)
return
}
log.Printf("[gRPC Stream] Group message received: group=%s, type=%v", msg.GroupId, msg.Type)
// Echo back for now
if err := stream.Send(msg); err != nil {
log.Printf("[gRPC Stream] Send error: %v", err)
return
}
}
}()
<-ctx.Done()
log.Printf("[gRPC Stream] Group stream closed: %s", clientID)
return nil
}
// InitiateVote initiates a voting process in the group
func (s *GroupServiceImpl) InitiateVote(ctx context.Context, req *VoteRequest) (*VoteResponse, error) {
voteID, err := s.groupManager.InitiateVote(ctx, req.GroupId, req.InitiatorId, req.Question, req.Options, req.Threshold, req.TimeoutSeconds)
if err != nil {
return &VoteResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &VoteResponse{
Success: true,
VoteId: voteID,
}, nil
}
// SubmitVote submits a vote in an ongoing voting process
func (s *GroupServiceImpl) SubmitVote(ctx context.Context, req *SubmitVoteRequest) (*SubmitVoteResponse, error) {
err := s.groupManager.SubmitVote(ctx, req.VoteId, req.AgentId, req.Option, req.Reason)
if err != nil {
return &SubmitVoteResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &SubmitVoteResponse{
Success: true,
}, nil
}
// GetVoteStatus gets the current status of a vote
func (s *GroupServiceImpl) GetVoteStatus(ctx context.Context, req *GetVoteStatusRequest) (*VoteStatusResponse, error) {
status, err := s.groupManager.GetVoteStatus(ctx, req.VoteId)
if err != nil {
return &VoteStatusResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &VoteStatusResponse{
Success: true,
VoteId: status.VoteID,
Status: status.Status,
Question: status.Question,
TotalVotes: int32(status.TotalVotes),
RequiredVotes: int32(status.RequiredVotes),
WinningOption: status.WinningOption,
}, nil
}
// SplitTask splits a task into subtasks across group members
func (s *GroupServiceImpl) SplitTask(ctx context.Context, req *SplitTaskRequest) (*SplitTaskResponse, error) {
subtasks, err := s.groupManager.SplitTask(ctx, req.GroupId, req.TaskId, req.TaskType, req.Requirements, req.Strategy)
if err != nil {
return &SplitTaskResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &SplitTaskResponse{
Success: true,
GroupId: req.GroupId,
ParentTaskId: req.TaskId,
Subtasks: subtasks,
}, nil
}
// MergeResults merges results from subtasks
func (s *GroupServiceImpl) MergeResults(ctx context.Context, req *MergeResultsRequest) (*MergeResultsResponse, error) {
mergedResult, summary, err := s.groupManager.MergeResults(ctx, req.GroupId, req.ParentTaskId, req.Strategy)
if err != nil {
return &MergeResultsResponse{
Success: false,
Error: err.Error(),
}, nil
}
return &MergeResultsResponse{
Success: true,
ParentTaskId: req.ParentTaskId,
MergedResult: mergedResult,
Summary: summary,
}, nil
}
// =============================================================================
// Health Service Implementation
// =============================================================================
type HealthServiceImpl struct {
UnimplementedHealthServiceServer
}
func (s *HealthServiceImpl) HealthCheck(ctx context.Context, req *emptypb.Empty) (*HealthCheckResponse, error) {
return &HealthCheckResponse{
Status: "healthy",
Version: "1.0.0",
UptimeSeconds: 3600,
ActiveTasks: 0,
}, nil
}
// =============================================================================
// Conversion Helpers
// =============================================================================
func parseTaskStatus(status string) TaskStatus {
switch status {
case "received":
return TaskStatus_TASK_STATUS_RECEIVED
case "processing":
return TaskStatus_TASK_STATUS_PROCESSING
case "completed":
return TaskStatus_TASK_STATUS_COMPLETED
case "failed":
return TaskStatus_TASK_STATUS_FAILED
case "cancelled":
return TaskStatus_TASK_STATUS_CANCELLED
case "rejected":
return TaskStatus_TASK_STATUS_REJECTED
case "waiting":
return TaskStatus_TASK_STATUS_WAITING
default:
return TaskStatus_TASK_STATUS_UNSPECIFIED
}
}
func convertTaskInfo(task *types.TaskInfo) *TaskInfo {
if task == nil {
return nil
}
var result *anypb.Any
if task.Result != nil {
result, _ = anypb.New(&anypb.Any{Value: []byte(fmt.Sprintf("%v", task.Result))})
}
return &TaskInfo{
Id: task.ID,
Type: task.Type,
Status: parseTaskStatus(task.Status),
Progress: int32(task.Progress),
Message: task.Message,
CreatedAt: timestamppb.Now(),
UpdatedAt: timestamppb.Now(),
Result: result,
}
}
func convertAgentCapabilities(caps *types.AgentCapabilities) *AgentCapabilities {
if caps == nil {
return nil
}
var taskTypes []*SupportedTaskType
for _, tt := range caps.SupportedTaskTypes {
taskTypes = append(taskTypes, &SupportedTaskType{
Type: tt.Type,
Name: tt.Name,
Description: tt.Description,
EstimatedTime: tt.EstimatedTime,
InputSchema: tt.InputSchema,
OutputSchema: tt.OutputSchema,
Capabilities: tt.Capabilities,
})
}
var transportModes []TransportMode
for _, tm := range caps.SupportedTransportModes {
transportModes = append(transportModes, TransportMode(TransportMode_value[string(tm)]))
}
return &AgentCapabilities{
AgentId: caps.AgentID,
AgentName: caps.AgentName,
SystemId: caps.SystemID,
ProtocolVersion: caps.ProtocolVersion,
SupportedTaskTypes: taskTypes,
SupportedContentTypes: caps.SupportedContentTypes,
SupportedTransportModes: transportModes,
MaxFileSize: caps.MaxFileSize,
MaxConcurrentTasks: int32(caps.MaxConcurrentTasks),
MaxTaskDurationSeconds: int32(caps.MaxTaskDuration),
SupportProgressUpdates: caps.SupportProgressUpdates,
SupportStreaming: caps.SupportStreaming,
SupportHil: caps.SupportHiL,
SupportGroups: caps.SupportGroups,
}
}
func convertProtoToInternalMessage(msg *A2AMessage) *types.UnifiedSynapseMessage {
if msg == nil {
return nil
}
var payload []byte
if msg.Payload != nil {
payload = msg.Payload.Value
}
return &types.UnifiedSynapseMessage{
ID: msg.Id,
Version: msg.Version,
Type: string(MessageType_name[int32(msg.Type)]),
Sender: types.AgentEndpoint{AgentID: msg.Sender.AgentId},
CorrelationID: msg.CorrelationId,
ReplyTo: msg.ReplyTo,
GroupID: msg.GroupId,
Timestamp: types.Timestamp(msg.Timestamp.AsTime().Format(time.RFC3339)),
Payload: payload,
Signature: msg.Signature,
}
}
func convertInternalToProtoMessage(msg *types.UnifiedSynapseMessage) *A2AMessage {
if msg == nil {
return nil
}
var payload *anypb.Any
if len(msg.Payload) > 0 {
payload = &anypb.Any{Value: msg.Payload}
}
return &A2AMessage{
Id: msg.ID,
Version: msg.Version,
Type: MessageType(MessageType_value[msg.Type]),
Sender: &AgentEndpoint{AgentId: msg.Sender.AgentID},
CorrelationId: msg.CorrelationID,
ReplyTo: msg.ReplyTo,
GroupId: msg.GroupID,
Timestamp: timestamppb.Now(),
Payload: payload,
Signature: msg.Signature,
}
}
func convertProtoEndpoint(endpoint *AgentEndpoint) *types.AgentEndpoint {
if endpoint == nil {
return nil
}
return &types.AgentEndpoint{
AgentID: endpoint.AgentId,
AgentName: endpoint.AgentName,
SystemID: endpoint.SystemId,
Endpoint: endpoint.Endpoint,
Version: endpoint.Version,
}
}

View File

@@ -0,0 +1,850 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// version: proto synapse v1.0.0
// This file contains manually created stubs matching proto/synapse.proto
package grpcapi
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
anypb "google.golang.org/protobuf/types/known/anypb"
timestamp "google.golang.org/protobuf/types/known/timestamppb"
)
// TransportMode represents the transport mode
type TransportMode int32
const (
TransportMode_TRANSPORT_MODE_UNSPECIFIED TransportMode = 0
TransportMode_TRANSPORT_MODE_CALLBACK TransportMode = 1
TransportMode_TRANSPORT_MODE_POLLING TransportMode = 2
TransportMode_TRANSPORT_MODE_SYNC TransportMode = 3
TransportMode_TRANSPORT_MODE_HYBRID TransportMode = 4
)
var TransportMode_name = map[int32]string{
0: "TRANSPORT_MODE_UNSPECIFIED",
1: "TRANSPORT_MODE_CALLBACK",
2: "TRANSPORT_MODE_POLLING",
3: "TRANSPORT_MODE_SYNC",
4: "TRANSPORT_MODE_HYBRID",
}
var TransportMode_value = map[string]int32{
"TRANSPORT_MODE_UNSPECIFIED": 0,
"TRANSPORT_MODE_CALLBACK": 1,
"TRANSPORT_MODE_POLLING": 2,
"TRANSPORT_MODE_SYNC": 3,
"TRANSPORT_MODE_HYBRID": 4,
}
// MessageType represents the type of Synapse message
type MessageType int32
const (
MessageType_MESSAGE_TYPE_UNSPECIFIED MessageType = 0
MessageType_MESSAGE_TYPE_P2P_TASK_REQUEST MessageType = 1
MessageType_MESSAGE_TYPE_P2P_TASK_COMPLETE MessageType = 2
MessageType_MESSAGE_TYPE_P2P_TASK_FAILED MessageType = 3
MessageType_MESSAGE_TYPE_P2P_STATUS_UPDATE MessageType = 4
MessageType_MESSAGE_TYPE_P2P_INFO_MISSING MessageType = 5
MessageType_MESSAGE_TYPE_P2P_ACK MessageType = 6
MessageType_MESSAGE_TYPE_P2P_NACK MessageType = 7
MessageType_MESSAGE_TYPE_GROUP_INVITE MessageType = 8
MessageType_MESSAGE_TYPE_GROUP_JOIN MessageType = 9
MessageType_MESSAGE_TYPE_GROUP_LEAVE MessageType = 10
MessageType_MESSAGE_TYPE_GROUP_TASK_SPLIT MessageType = 11
MessageType_MESSAGE_TYPE_GROUP_SUBTASK_RESULT MessageType = 12
MessageType_MESSAGE_TYPE_GROUP_RESULT_MERGE MessageType = 13
MessageType_MESSAGE_TYPE_GROUP_VOTE_INITIATE MessageType = 14
MessageType_MESSAGE_TYPE_GROUP_VOTE_SUBMIT MessageType = 15
MessageType_MESSAGE_TYPE_GROUP_VOTE_RESULT MessageType = 16
MessageType_MESSAGE_TYPE_HIL_DECISION_REQUEST MessageType = 17
MessageType_MESSAGE_TYPE_HIL_DECISION_RESPONSE MessageType = 18
MessageType_MESSAGE_TYPE_HEARTBEAT MessageType = 19
)
var MessageType_name = map[int32]string{
0: "MESSAGE_TYPE_UNSPECIFIED",
1: "MESSAGE_TYPE_P2P_TASK_REQUEST",
2: "MESSAGE_TYPE_P2P_TASK_COMPLETE",
3: "MESSAGE_TYPE_P2P_TASK_FAILED",
4: "MESSAGE_TYPE_P2P_STATUS_UPDATE",
5: "MESSAGE_TYPE_P2P_INFO_MISSING",
6: "MESSAGE_TYPE_P2P_ACK",
7: "MESSAGE_TYPE_P2P_NACK",
8: "MESSAGE_TYPE_GROUP_INVITE",
9: "MESSAGE_TYPE_GROUP_JOIN",
10: "MESSAGE_TYPE_GROUP_LEAVE",
11: "MESSAGE_TYPE_GROUP_TASK_SPLIT",
12: "MESSAGE_TYPE_GROUP_SUBTASK_RESULT",
13: "MESSAGE_TYPE_GROUP_RESULT_MERGE",
14: "MESSAGE_TYPE_GROUP_VOTE_INITIATE",
15: "MESSAGE_TYPE_GROUP_VOTE_SUBMIT",
16: "MESSAGE_TYPE_GROUP_VOTE_RESULT",
17: "MESSAGE_TYPE_HIL_DECISION_REQUEST",
18: "MESSAGE_TYPE_HIL_DECISION_RESPONSE",
19: "MESSAGE_TYPE_HEARTBEAT",
}
var MessageType_value = map[string]int32{
"MESSAGE_TYPE_UNSPECIFIED": 0,
"MESSAGE_TYPE_P2P_TASK_REQUEST": 1,
"MESSAGE_TYPE_P2P_TASK_COMPLETE": 2,
"MESSAGE_TYPE_P2P_TASK_FAILED": 3,
"MESSAGE_TYPE_P2P_STATUS_UPDATE": 4,
"MESSAGE_TYPE_P2P_INFO_MISSING": 5,
"MESSAGE_TYPE_P2P_ACK": 6,
"MESSAGE_TYPE_P2P_NACK": 7,
"MESSAGE_TYPE_GROUP_INVITE": 8,
"MESSAGE_TYPE_GROUP_JOIN": 9,
"MESSAGE_TYPE_GROUP_LEAVE": 10,
"MESSAGE_TYPE_GROUP_TASK_SPLIT": 11,
"MESSAGE_TYPE_GROUP_SUBTASK_RESULT": 12,
"MESSAGE_TYPE_GROUP_RESULT_MERGE": 13,
"MESSAGE_TYPE_GROUP_VOTE_INITIATE": 14,
"MESSAGE_TYPE_GROUP_VOTE_SUBMIT": 15,
"MESSAGE_TYPE_GROUP_VOTE_RESULT": 16,
"MESSAGE_TYPE_HIL_DECISION_REQUEST": 17,
"MESSAGE_TYPE_HIL_DECISION_RESPONSE": 18,
"MESSAGE_TYPE_HEARTBEAT": 19,
}
// TaskStatus represents the status of a task
type TaskStatus int32
const (
TaskStatus_TASK_STATUS_UNSPECIFIED TaskStatus = 0
TaskStatus_TASK_STATUS_RECEIVED TaskStatus = 1
TaskStatus_TASK_STATUS_PROCESSING TaskStatus = 2
TaskStatus_TASK_STATUS_COMPLETED TaskStatus = 3
TaskStatus_TASK_STATUS_FAILED TaskStatus = 4
TaskStatus_TASK_STATUS_CANCELLED TaskStatus = 5
TaskStatus_TASK_STATUS_REJECTED TaskStatus = 6
TaskStatus_TASK_STATUS_WAITING TaskStatus = 7
)
var TaskStatus_name = map[int32]string{
0: "TASK_STATUS_UNSPECIFIED",
1: "TASK_STATUS_RECEIVED",
2: "TASK_STATUS_PROCESSING",
3: "TASK_STATUS_COMPLETED",
4: "TASK_STATUS_FAILED",
5: "TASK_STATUS_CANCELLED",
6: "TASK_STATUS_REJECTED",
7: "TASK_STATUS_WAITING",
}
var TaskStatus_value = map[string]int32{
"TASK_STATUS_UNSPECIFIED": 0,
"TASK_STATUS_RECEIVED": 1,
"TASK_STATUS_PROCESSING": 2,
"TASK_STATUS_COMPLETED": 3,
"TASK_STATUS_FAILED": 4,
"TASK_STATUS_CANCELLED": 5,
"TASK_STATUS_REJECTED": 6,
"TASK_STATUS_WAITING": 7,
}
func (x TransportMode) String() string { return fmt.Sprintf("%v", x) }
func (x MessageType) String() string { return fmt.Sprintf("%v", x) }
func (x TaskStatus) String() string { return fmt.Sprintf("%v", x) }
func init() {
proto.RegisterEnum("a2a.TransportMode", TransportMode_name, TransportMode_value)
proto.RegisterEnum("a2a.MessageType", MessageType_name, MessageType_value)
proto.RegisterEnum("a2a.TaskStatus", TaskStatus_name, TaskStatus_value)
}
// AgentEndpoint represents an agent's endpoint
type AgentEndpoint struct {
AgentId string `protobuf:"bytes,1,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
AgentName string `protobuf:"bytes,2,opt,name=agent_name,json=agentName" json:"agent_name,omitempty"`
SystemId string `protobuf:"bytes,3,opt,name=system_id,json=systemId" json:"system_id,omitempty"`
Endpoint string `protobuf:"bytes,4,opt,name=endpoint" json:"endpoint,omitempty"`
Version string `protobuf:"bytes,5,opt,name=version" json:"version,omitempty"`
}
func (m *AgentEndpoint) Reset() { *m = AgentEndpoint{} }
func (m *AgentEndpoint) String() string { return fmt.Sprintf("%+v", m) }
func (*AgentEndpoint) ProtoMessage() {}
func (m *AgentEndpoint) GetAgentId() string {
if m != nil {
return m.AgentId
}
return ""
}
// A2AMessage represents a complete Synapse message
type A2AMessage struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Version string `protobuf:"bytes,2,opt,name=version" json:"version,omitempty"`
Type MessageType `protobuf:"varint,3,opt,name=type,enum=a2a.MessageType" json:"type,omitempty"`
Sender *AgentEndpoint `protobuf:"bytes,4,opt,name=sender" json:"sender,omitempty"`
Receiver *AgentEndpoint `protobuf:"bytes,5,opt,name=receiver" json:"receiver,omitempty"`
CorrelationId string `protobuf:"bytes,6,opt,name=correlation_id,json=correlationId" json:"correlation_id,omitempty"`
ReplyTo string `protobuf:"bytes,7,opt,name=reply_to,json=replyTo" json:"reply_to,omitempty"`
GroupId string `protobuf:"bytes,8,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
Timestamp *timestamp.Timestamp `protobuf:"bytes,9,opt,name=timestamp" json:"timestamp,omitempty"`
Payload *anypb.Any `protobuf:"bytes,10,opt,name=payload" json:"payload,omitempty"`
Signature string `protobuf:"bytes,11,opt,name=signature" json:"signature,omitempty"`
}
func (m *A2AMessage) Reset() { *m = A2AMessage{} }
func (m *A2AMessage) String() string { return fmt.Sprintf("%+v", m) }
func (*A2AMessage) ProtoMessage() {}
// TaskPayload represents task submission payload
type TaskPayload struct {
TaskId string `protobuf:"bytes,1,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
TaskType string `protobuf:"bytes,2,opt,name=task_type,json=taskType" json:"task_type,omitempty"`
Payload *anypb.Any `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
ExternalTaskId string `protobuf:"bytes,4,opt,name=external_task_id,json=externalTaskId" json:"external_task_id,omitempty"`
}
func (m *TaskPayload) Reset() { *m = TaskPayload{} }
func (m *TaskPayload) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskPayload) ProtoMessage() {}
// TaskResult represents task result
type TaskResult struct {
TaskId string `protobuf:"bytes,1,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type" json:"type,omitempty"`
Result *anypb.Any `protobuf:"bytes,3,opt,name=result" json:"result,omitempty"`
Summary string `protobuf:"bytes,4,opt,name=summary" json:"summary,omitempty"`
}
func (m *TaskResult) Reset() { *m = TaskResult{} }
func (m *TaskResult) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskResult) ProtoMessage() {}
// TaskStatusUpdate represents task status update
type TaskStatusUpdate struct {
TaskId string `protobuf:"bytes,1,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
Status TaskStatus `protobuf:"varint,2,opt,name=status,enum=a2a.TaskStatus" json:"status,omitempty"`
Progress int32 `protobuf:"varint,3,opt,name=progress" json:"progress,omitempty"`
Message string `protobuf:"bytes,4,opt,name=message" json:"message,omitempty"`
Details *anypb.Any `protobuf:"bytes,5,opt,name=details" json:"details,omitempty"`
}
func (m *TaskStatusUpdate) Reset() { *m = TaskStatusUpdate{} }
func (m *TaskStatusUpdate) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskStatusUpdate) ProtoMessage() {}
// =============================================================================
// Task Service Messages
// =============================================================================
// SubmitTaskRequest is the request for submitting a task
type SubmitTaskRequest struct {
TaskType string `protobuf:"bytes,1,opt,name=task_type,json=taskType" json:"task_type,omitempty"`
Payload *anypb.Any `protobuf:"bytes,2,opt,name=payload" json:"payload,omitempty"`
ExternalTaskId string `protobuf:"bytes,3,opt,name=external_task_id,json=externalTaskId" json:"external_task_id,omitempty"`
Priority string `protobuf:"bytes,4,opt,name=priority" json:"priority,omitempty"`
CallbackUrl string `protobuf:"bytes,5,opt,name=callback_url,json=callbackUrl" json:"callback_url,omitempty"`
CallbackToken string `protobuf:"bytes,6,opt,name=callback_token,json=callbackToken" json:"callback_token,omitempty"`
PreferredTransport TransportMode `protobuf:"varint,7,opt,name=preferred_transport,json=preferredTransport" json:"preferred_transport,omitempty"`
}
func (m *SubmitTaskRequest) Reset() { *m = SubmitTaskRequest{} }
func (m *SubmitTaskRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*SubmitTaskRequest) ProtoMessage() {}
func (m *SubmitTaskRequest) GetTaskType() string {
if m != nil {
return m.TaskType
}
return ""
}
// SubmitTaskResponse is the response for task submission
type SubmitTaskResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
TaskId string `protobuf:"bytes,2,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
Status TaskStatus `protobuf:"varint,3,opt,name=status,enum=a2a.TaskStatus" json:"status,omitempty"`
Message string `protobuf:"bytes,4,opt,name=message" json:"message,omitempty"`
ErrorCode string `protobuf:"bytes,5,opt,name=error_code,json=errorCode" json:"error_code,omitempty"`
}
func (m *SubmitTaskResponse) Reset() { *m = SubmitTaskResponse{} }
func (m *SubmitTaskResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*SubmitTaskResponse) ProtoMessage() {}
// SubmitTaskWithFilesRequest is the request for submitting a task with files
type SubmitTaskWithFilesRequest struct {
Request *SubmitTaskRequest `protobuf:"bytes,1,opt,name=request" json:"request,omitempty"`
Files []*FileUpload `protobuf:"bytes,2,rep,name=files" json:"files,omitempty"`
}
func (m *SubmitTaskWithFilesRequest) Reset() { *m = SubmitTaskWithFilesRequest{} }
func (m *SubmitTaskWithFilesRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*SubmitTaskWithFilesRequest) ProtoMessage() {}
// FileUpload represents an uploaded file
type FileUpload struct {
FieldName string `protobuf:"bytes,1,opt,name=field_name,json=fieldName" json:"field_name,omitempty"`
Filename string `protobuf:"bytes,2,opt,name=filename" json:"filename,omitempty"`
MimeType string `protobuf:"bytes,3,opt,name=mime_type,json=mimeType" json:"mime_type,omitempty"`
Data []byte `protobuf:"bytes,4,opt,name=data" json:"data,omitempty"`
}
func (m *FileUpload) Reset() { *m = FileUpload{} }
func (m *FileUpload) String() string { return fmt.Sprintf("%+v", m) }
func (*FileUpload) ProtoMessage() {}
// GetTaskRequest is the request for getting task details
type GetTaskRequest struct {
TaskId string `protobuf:"bytes,1,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
}
func (m *GetTaskRequest) Reset() { *m = GetTaskRequest{} }
func (m *GetTaskRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*GetTaskRequest) ProtoMessage() {}
// TaskStatusResponse is the response for task status query
type TaskStatusResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Task *TaskInfo `protobuf:"bytes,2,opt,name=task" json:"task,omitempty"`
ErrorCode string `protobuf:"bytes,3,opt,name=error_code,json=errorCode" json:"error_code,omitempty"`
ErrorMessage string `protobuf:"bytes,4,opt,name=error_message,json=errorMessage" json:"error_message,omitempty"`
}
func (m *TaskStatusResponse) Reset() { *m = TaskStatusResponse{} }
func (m *TaskStatusResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskStatusResponse) ProtoMessage() {}
// TaskInfo represents task information
type TaskInfo struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type" json:"type,omitempty"`
Status TaskStatus `protobuf:"varint,3,opt,name=status,enum=a2a.TaskStatus" json:"status,omitempty"`
Progress int32 `protobuf:"varint,4,opt,name=progress" json:"progress,omitempty"`
Message string `protobuf:"bytes,5,opt,name=message" json:"message,omitempty"`
CreatedAt *timestamp.Timestamp `protobuf:"bytes,6,opt,name=created_at,json=createdAt" json:"created_at,omitempty"`
UpdatedAt *timestamp.Timestamp `protobuf:"bytes,7,opt,name=updated_at,json=updatedAt" json:"updated_at,omitempty"`
CompletedAt *timestamp.Timestamp `protobuf:"bytes,8,opt,name=completed_at,json=completedAt" json:"completed_at,omitempty"`
ETA *timestamp.Timestamp `protobuf:"bytes,9,opt,name=e_t_a,json=eta" json:"eta,omitempty"`
Result *anypb.Any `protobuf:"bytes,10,opt,name=result" json:"result,omitempty"`
Error *TaskError `protobuf:"bytes,11,opt,name=error" json:"error,omitempty"`
ExternalTaskId string `protobuf:"bytes,12,opt,name=external_task_id,json=externalTaskId" json:"external_task_id,omitempty"`
}
func (m *TaskInfo) Reset() { *m = TaskInfo{} }
func (m *TaskInfo) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskInfo) ProtoMessage() {}
// TaskError represents a task error
type TaskError struct {
Code string `protobuf:"bytes,1,opt,name=code" json:"code,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"`
}
func (m *TaskError) Reset() { *m = TaskError{} }
func (m *TaskError) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskError) ProtoMessage() {}
// ListTasksRequest is the request for listing tasks
type ListTasksRequest struct {
Status string `protobuf:"bytes,1,opt,name=status" json:"status,omitempty"`
Limit int32 `protobuf:"varint,2,opt,name=limit" json:"limit,omitempty"`
Offset int32 `protobuf:"varint,3,opt,name=offset" json:"offset,omitempty"`
}
func (m *ListTasksRequest) Reset() { *m = ListTasksRequest{} }
func (m *ListTasksRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*ListTasksRequest) ProtoMessage() {}
// ListTasksResponse is the response for listing tasks
type ListTasksResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Tasks []*TaskInfo `protobuf:"bytes,2,rep,name=tasks" json:"tasks,omitempty"`
Total int32 `protobuf:"varint,3,opt,name=total" json:"total,omitempty"`
Limit int32 `protobuf:"varint,4,opt,name=limit" json:"limit,omitempty"`
Offset int32 `protobuf:"varint,5,opt,name=offset" json:"offset,omitempty"`
HasMore bool `protobuf:"varint,6,opt,name=has_more,json=hasMore" json:"has_more,omitempty"`
}
func (m *ListTasksResponse) Reset() { *m = ListTasksResponse{} }
func (m *ListTasksResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*ListTasksResponse) ProtoMessage() {}
// CancelTaskRequest is the request for cancelling a task
type CancelTaskRequest struct {
TaskId string `protobuf:"bytes,1,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
}
func (m *CancelTaskRequest) Reset() { *m = CancelTaskRequest{} }
func (m *CancelTaskRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*CancelTaskRequest) ProtoMessage() {}
// CancelTaskResponse is the response for cancelling a task
type CancelTaskResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
TaskId string `protobuf:"bytes,2,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
Status TaskStatus `protobuf:"varint,3,opt,name=status,enum=a2a.TaskStatus" json:"status,omitempty"`
Message string `protobuf:"bytes,4,opt,name=message" json:"message,omitempty"`
}
func (m *CancelTaskResponse) Reset() { *m = CancelTaskResponse{} }
func (m *CancelTaskResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*CancelTaskResponse) ProtoMessage() {}
// TaskStatusStreamRequest is the request for streaming task status
type TaskStatusStreamRequest struct {
TaskId string `protobuf:"bytes,1,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
Subscribe bool `protobuf:"varint,2,opt,name=subscribe" json:"subscribe,omitempty"`
}
func (m *TaskStatusStreamRequest) Reset() { *m = TaskStatusStreamRequest{} }
func (m *TaskStatusStreamRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*TaskStatusStreamRequest) ProtoMessage() {}
// =============================================================================
// Synapse Message Service Messages
// =============================================================================
// SendMessageRequest is the request for sending an Synapse message
type SendMessageRequest struct {
Message *A2AMessage `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
}
func (m *SendMessageRequest) Reset() { *m = SendMessageRequest{} }
func (m *SendMessageRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*SendMessageRequest) ProtoMessage() {}
// SendMessageResponse is the response for sending an Synapse message
type SendMessageResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
MessageId string `protobuf:"bytes,2,opt,name=message_id,json=messageId" json:"message_id,omitempty"`
Error string `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"`
}
func (m *SendMessageResponse) Reset() { *m = SendMessageResponse{} }
func (m *SendMessageResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*SendMessageResponse) ProtoMessage() {}
// =============================================================================
// Capabilities Service Messages
// =============================================================================
// CapabilitiesResponse is the response for capabilities query
type CapabilitiesResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Capabilities *AgentCapabilities `protobuf:"bytes,2,opt,name=capabilities" json:"capabilities,omitempty"`
Error string `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"`
}
func (m *CapabilitiesResponse) Reset() { *m = CapabilitiesResponse{} }
func (m *CapabilitiesResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*CapabilitiesResponse) ProtoMessage() {}
// AgentCapabilities represents agent capabilities
type AgentCapabilities struct {
AgentId string `protobuf:"bytes,1,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
AgentName string `protobuf:"bytes,2,opt,name=agent_name,json=agentName" json:"agent_name,omitempty"`
SystemId string `protobuf:"bytes,3,opt,name=system_id,json=systemId" json:"system_id,omitempty"`
ProtocolVersion string `protobuf:"bytes,4,opt,name=protocol_version,json=protocolVersion" json:"protocol_version,omitempty"`
SupportedTaskTypes []*SupportedTaskType `protobuf:"bytes,5,rep,name=supported_task_types,json=supportedTaskTypes" json:"supported_task_types,omitempty"`
SupportedContentTypes []string `protobuf:"bytes,6,rep,name=supported_content_types,json=supportedContentTypes" json:"supported_content_types,omitempty"`
SupportedTransportModes []TransportMode `protobuf:"varint,7,rep,name=supported_transport_modes,json=supportedTransportModes" json:"supported_transport_modes,omitempty"`
MaxFileSize int64 `protobuf:"varint,8,opt,name=max_file_size,json=maxFileSize" json:"max_file_size,omitempty"`
MaxConcurrentTasks int32 `protobuf:"varint,9,opt,name=max_concurrent_tasks,json=maxConcurrentTasks" json:"max_concurrent_tasks,omitempty"`
MaxTaskDurationSeconds int32 `protobuf:"varint,10,opt,name=max_task_duration_seconds,json=maxTaskDurationSeconds" json:"max_task_duration_seconds,omitempty"`
SupportProgressUpdates bool `protobuf:"varint,11,opt,name=support_progress_updates,json=supportProgressUpdates" json:"support_progress_updates,omitempty"`
SupportStreaming bool `protobuf:"varint,12,opt,name=support_streaming,json=supportStreaming" json:"support_streaming,omitempty"`
SupportHil bool `protobuf:"varint,13,opt,name=support_hil,json=supportHil" json:"support_hil,omitempty"`
SupportGroups bool `protobuf:"varint,14,opt,name=support_groups,json=supportGroups" json:"support_groups,omitempty"`
}
func (m *AgentCapabilities) Reset() { *m = AgentCapabilities{} }
func (m *AgentCapabilities) String() string { return fmt.Sprintf("%+v", m) }
func (*AgentCapabilities) ProtoMessage() {}
// SupportedTaskType represents a supported task type
type SupportedTaskType struct {
Type string `protobuf:"bytes,1,opt,name=type" json:"type,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description" json:"description,omitempty"`
EstimatedTime string `protobuf:"bytes,4,opt,name=estimated_time,json=estimatedTime" json:"estimated_time,omitempty"`
InputSchema string `protobuf:"bytes,5,opt,name=input_schema,json=inputSchema" json:"input_schema,omitempty"`
OutputSchema string `protobuf:"bytes,6,opt,name=output_schema,json=outputSchema" json:"output_schema,omitempty"`
Capabilities []string `protobuf:"bytes,7,rep,name=capabilities" json:"capabilities,omitempty"`
}
func (m *SupportedTaskType) Reset() { *m = SupportedTaskType{} }
func (m *SupportedTaskType) String() string { return fmt.Sprintf("%+v", m) }
func (*SupportedTaskType) ProtoMessage() {}
// QueryAgentRequest is the request for querying an agent
type QueryAgentRequest struct {
AgentId string `protobuf:"bytes,1,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
}
func (m *QueryAgentRequest) Reset() { *m = QueryAgentRequest{} }
func (m *QueryAgentRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*QueryAgentRequest) ProtoMessage() {}
// ListAgentsResponse is the response for listing agents
type ListAgentsResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Agents []*AgentInfo `protobuf:"bytes,2,rep,name=agents" json:"agents,omitempty"`
Total int32 `protobuf:"varint,3,opt,name=total" json:"total,omitempty"`
}
func (m *ListAgentsResponse) Reset() { *m = ListAgentsResponse{} }
func (m *ListAgentsResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*ListAgentsResponse) ProtoMessage() {}
// AgentInfo represents agent information
type AgentInfo struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
AgentId string `protobuf:"bytes,2,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
AgentName string `protobuf:"bytes,3,opt,name=agent_name,json=agentName" json:"agent_name,omitempty"`
SystemId string `protobuf:"bytes,4,opt,name=system_id,json=systemId" json:"system_id,omitempty"`
Endpoint string `protobuf:"bytes,5,opt,name=endpoint" json:"endpoint,omitempty"`
IsActive bool `protobuf:"varint,6,opt,name=is_active,json=isActive" json:"is_active,omitempty"`
TrustLevel int32 `protobuf:"varint,7,opt,name=trust_level,json=trustLevel" json:"trust_level,omitempty"`
}
func (m *AgentInfo) Reset() { *m = AgentInfo{} }
func (m *AgentInfo) String() string { return fmt.Sprintf("%+v", m) }
func (*AgentInfo) ProtoMessage() {}
// =============================================================================
// Group Service Messages
// =============================================================================
// CreateGroupRequest is the request for creating a group
type CreateGroupRequest struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description" json:"description,omitempty"`
CoordinatorId string `protobuf:"bytes,3,opt,name=coordinator_id,json=coordinatorId" json:"coordinator_id,omitempty"`
InitialMembers []string `protobuf:"bytes,4,rep,name=initial_members,json=initialMembers" json:"initial_members,omitempty"`
}
func (m *CreateGroupRequest) Reset() { *m = CreateGroupRequest{} }
func (m *CreateGroupRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*CreateGroupRequest) ProtoMessage() {}
// CreateGroupResponse is the response for creating a group
type CreateGroupResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
GroupId string `protobuf:"bytes,2,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
Group *GroupInfo `protobuf:"bytes,3,opt,name=group" json:"group,omitempty"`
Error string `protobuf:"bytes,4,opt,name=error" json:"error,omitempty"`
}
func (m *CreateGroupResponse) Reset() { *m = CreateGroupResponse{} }
func (m *CreateGroupResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*CreateGroupResponse) ProtoMessage() {}
// GroupInfo represents group information
type GroupInfo struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description" json:"description,omitempty"`
CoordinatorId string `protobuf:"bytes,4,opt,name=coordinator_id,json=coordinatorId" json:"coordinator_id,omitempty"`
Status string `protobuf:"bytes,5,opt,name=status" json:"status,omitempty"`
CreatedAt *timestamp.Timestamp `protobuf:"bytes,6,opt,name=created_at,json=createdAt" json:"created_at,omitempty"`
}
func (m *GroupInfo) Reset() { *m = GroupInfo{} }
func (m *GroupInfo) String() string { return fmt.Sprintf("%+v", m) }
func (*GroupInfo) ProtoMessage() {}
// JoinGroupRequest is the request for joining a group
type JoinGroupRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
Agent *AgentEndpoint `protobuf:"bytes,2,opt,name=agent" json:"agent,omitempty"`
}
func (m *JoinGroupRequest) Reset() { *m = JoinGroupRequest{} }
func (m *JoinGroupRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*JoinGroupRequest) ProtoMessage() {}
// JoinGroupResponse is the response for joining a group
type JoinGroupResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"`
}
func (m *JoinGroupResponse) Reset() { *m = JoinGroupResponse{} }
func (m *JoinGroupResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*JoinGroupResponse) ProtoMessage() {}
// LeaveGroupRequest is the request for leaving a group
type LeaveGroupRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
AgentId string `protobuf:"bytes,2,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
}
func (m *LeaveGroupRequest) Reset() { *m = LeaveGroupRequest{} }
func (m *LeaveGroupRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*LeaveGroupRequest) ProtoMessage() {}
// LeaveGroupResponse is the response for leaving a group
type LeaveGroupResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"`
}
func (m *LeaveGroupResponse) Reset() { *m = LeaveGroupResponse{} }
func (m *LeaveGroupResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*LeaveGroupResponse) ProtoMessage() {}
// DisbandGroupRequest is the request for disbanding a group
type DisbandGroupRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
}
func (m *DisbandGroupRequest) Reset() { *m = DisbandGroupRequest{} }
func (m *DisbandGroupRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*DisbandGroupRequest) ProtoMessage() {}
// DisbandGroupResponse is the response for disbanding a group
type DisbandGroupResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"`
}
func (m *DisbandGroupResponse) Reset() { *m = DisbandGroupResponse{} }
func (m *DisbandGroupResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*DisbandGroupResponse) ProtoMessage() {}
// ListGroupMembersRequest is the request for listing group members
type ListGroupMembersRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
}
func (m *ListGroupMembersRequest) Reset() { *m = ListGroupMembersRequest{} }
func (m *ListGroupMembersRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*ListGroupMembersRequest) ProtoMessage() {}
// ListGroupMembersResponse is the response for listing group members
type ListGroupMembersResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Members []*GroupMember `protobuf:"bytes,2,rep,name=members" json:"members,omitempty"`
}
func (m *ListGroupMembersResponse) Reset() { *m = ListGroupMembersResponse{} }
func (m *ListGroupMembersResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*ListGroupMembersResponse) ProtoMessage() {}
// GroupMember represents a group member
type GroupMember struct {
AgentId string `protobuf:"bytes,1,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
AgentName string `protobuf:"bytes,2,opt,name=agent_name,json=agentName" json:"agent_name,omitempty"`
Role string `protobuf:"bytes,3,opt,name=role" json:"role,omitempty"`
Status string `protobuf:"bytes,4,opt,name=status" json:"status,omitempty"`
JoinedAt *timestamp.Timestamp `protobuf:"bytes,5,opt,name=joined_at,json=joinedAt" json:"joined_at,omitempty"`
}
func (m *GroupMember) Reset() { *m = GroupMember{} }
func (m *GroupMember) String() string { return fmt.Sprintf("%+v", m) }
func (*GroupMember) ProtoMessage() {}
// =============================================================================
// Group Voting Messages (NEW!)
// =============================================================================
// VoteRequest is the request for initiating a vote
type VoteRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
InitiatorId string `protobuf:"bytes,2,opt,name=initiator_id,json=initiatorId" json:"initiator_id,omitempty"`
Question string `protobuf:"bytes,3,opt,name=question" json:"question,omitempty"`
Options []string `protobuf:"bytes,4,rep,name=options" json:"options,omitempty"`
Threshold float64 `protobuf:"fixed64,5,opt,name=threshold" json:"threshold,omitempty"`
TimeoutSeconds int32 `protobuf:"varint,6,opt,name=timeout_seconds,json=timeoutSeconds" json:"timeout_seconds,omitempty"`
}
func (m *VoteRequest) Reset() { *m = VoteRequest{} }
func (m *VoteRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*VoteRequest) ProtoMessage() {}
// VoteResponse is the response for initiating a vote
type VoteResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
VoteId string `protobuf:"bytes,2,opt,name=vote_id,json=voteId" json:"vote_id,omitempty"`
Error string `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"`
}
func (m *VoteResponse) Reset() { *m = VoteResponse{} }
func (m *VoteResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*VoteResponse) ProtoMessage() {}
// SubmitVoteRequest is the request for submitting a vote
type SubmitVoteRequest struct {
VoteId string `protobuf:"bytes,1,opt,name=vote_id,json=voteId" json:"vote_id,omitempty"`
AgentId string `protobuf:"bytes,2,opt,name=agent_id,json=agentId" json:"agent_id,omitempty"`
Option string `protobuf:"bytes,3,opt,name=option" json:"option,omitempty"`
Reason string `protobuf:"bytes,4,opt,name=reason" json:"reason,omitempty"`
}
func (m *SubmitVoteRequest) Reset() { *m = SubmitVoteRequest{} }
func (m *SubmitVoteRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*SubmitVoteRequest) ProtoMessage() {}
// SubmitVoteResponse is the response for submitting a vote
type SubmitVoteResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"`
}
func (m *SubmitVoteResponse) Reset() { *m = SubmitVoteResponse{} }
func (m *SubmitVoteResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*SubmitVoteResponse) ProtoMessage() {}
// GetVoteStatusRequest is the request for getting vote status
type GetVoteStatusRequest struct {
VoteId string `protobuf:"bytes,1,opt,name=vote_id,json=voteId" json:"vote_id,omitempty"`
}
func (m *GetVoteStatusRequest) Reset() { *m = GetVoteStatusRequest{} }
func (m *GetVoteStatusRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*GetVoteStatusRequest) ProtoMessage() {}
// VoteStatusResponse is the response for vote status
type VoteStatusResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
VoteId string `protobuf:"bytes,2,opt,name=vote_id,json=voteId" json:"vote_id,omitempty"`
Status string `protobuf:"bytes,3,opt,name=status" json:"status,omitempty"` // open, decided, expired
Question string `protobuf:"bytes,4,opt,name=question" json:"question,omitempty"`
TotalVotes int32 `protobuf:"varint,5,opt,name=total_votes,json=totalVotes" json:"total_votes,omitempty"`
RequiredVotes int32 `protobuf:"varint,6,opt,name=required_votes,json=requiredVotes" json:"required_votes,omitempty"`
WinningOption string `protobuf:"bytes,7,opt,name=winning_option,json=winningOption" json:"winning_option,omitempty"`
Error string `protobuf:"bytes,8,opt,name=error" json:"error,omitempty"`
}
func (m *VoteStatusResponse) Reset() { *m = VoteStatusResponse{} }
func (m *VoteStatusResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*VoteStatusResponse) ProtoMessage() {}
// =============================================================================
// Task Split Messages (NEW!)
// =============================================================================
// SplitTaskRequest is the request for splitting a task
type SplitTaskRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
TaskId string `protobuf:"bytes,2,opt,name=task_id,json=taskId" json:"task_id,omitempty"`
TaskType string `protobuf:"bytes,3,opt,name=task_type,json=taskType" json:"task_type,omitempty"`
Requirements string `protobuf:"bytes,4,opt,name=requirements" json:"requirements,omitempty"`
Strategy SplitStrategy `protobuf:"varint,5,opt,name=strategy,enum=a2a.SplitStrategy" json:"strategy,omitempty"`
}
func (m *SplitTaskRequest) Reset() { *m = SplitTaskRequest{} }
func (m *SplitTaskRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*SplitTaskRequest) ProtoMessage() {}
type SplitStrategy int32
const (
SplitStrategy_SPLIT_BY_TYPE SplitStrategy = 0
SplitStrategy_SPLIT_BY_DATA SplitStrategy = 1
SplitStrategy_SPLIT_BY_REGION SplitStrategy = 2
SplitStrategy_SPLIT_BY_ROUNDROBIN SplitStrategy = 3
)
// SplitTaskResponse is the response for splitting a task
type SplitTaskResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
GroupId string `protobuf:"bytes,2,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
ParentTaskId string `protobuf:"bytes,3,opt,name=parent_task_id,json=parentTaskId" json:"parent_task_id,omitempty"`
Subtasks []*SubtaskInfo `protobuf:"bytes,4,rep,name=subtasks" json:"subtasks,omitempty"`
Error string `protobuf:"bytes,5,opt,name=error" json:"error,omitempty"`
}
func (m *SplitTaskResponse) Reset() { *m = SplitTaskResponse{} }
func (m *SplitTaskResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*SplitTaskResponse) ProtoMessage() {}
type SubtaskInfo struct {
SubtaskId string `protobuf:"bytes,1,opt,name=subtask_id,json=subtaskId" json:"subtask_id,omitempty"`
Assignee string `protobuf:"bytes,2,opt,name=assignee" json:"assignee,omitempty"`
Scope string `protobuf:"bytes,3,opt,name=scope" json:"scope,omitempty"`
Dependencies []string `protobuf:"bytes,4,rep,name=dependencies" json:"dependencies,omitempty"`
}
func (m *SubtaskInfo) Reset() { *m = SubtaskInfo{} }
func (m *SubtaskInfo) String() string { return fmt.Sprintf("%+v", m) }
func (*SubtaskInfo) ProtoMessage() {}
// MergeResultsRequest is the request for merging results
type MergeResultsRequest struct {
GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId" json:"group_id,omitempty"`
ParentTaskId string `protobuf:"bytes,2,opt,name=parent_task_id,json=parentTaskId" json:"parent_task_id,omitempty"`
Strategy MergeStrategy `protobuf:"varint,3,opt,name=strategy,enum=a2a.MergeStrategy" json:"strategy,omitempty"`
}
func (m *MergeResultsRequest) Reset() { *m = MergeResultsRequest{} }
func (m *MergeResultsRequest) String() string { return fmt.Sprintf("%+v", m) }
func (*MergeResultsRequest) ProtoMessage() {}
type MergeStrategy int32
const (
MergeStrategy_MERGE_ALL MergeStrategy = 0
MergeStrategy_MERGE_BEST MergeStrategy = 1
MergeStrategy_MERGE_CONSENSUS MergeStrategy = 2
MergeStrategy_MERGE_AGGREGATE MergeStrategy = 3
)
// MergeResultsResponse is the response for merging results
type MergeResultsResponse struct {
Success bool `protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
ParentTaskId string `protobuf:"bytes,2,opt,name=parent_task_id,json=parentTaskId" json:"parent_task_id,omitempty"`
MergedResult *anypb.Any `protobuf:"bytes,3,opt,name=merged_result,json=mergedResult" json:"merged_result,omitempty"`
Summary string `protobuf:"bytes,4,opt,name=summary" json:"summary,omitempty"`
Error string `protobuf:"bytes,5,opt,name=error" json:"error,omitempty"`
}
func (m *MergeResultsResponse) Reset() { *m = MergeResultsResponse{} }
func (m *MergeResultsResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*MergeResultsResponse) ProtoMessage() {}
// =============================================================================
// Health Service Messages
// =============================================================================
// HealthCheckResponse is the response for health check
type HealthCheckResponse struct {
Status string `protobuf:"bytes,1,opt,name=status" json:"status,omitempty"`
Version string `protobuf:"bytes,2,opt,name=version" json:"version,omitempty"`
UptimeSeconds int64 `protobuf:"varint,3,opt,name=uptime_seconds,json=uptimeSeconds" json:"uptime_seconds,omitempty"`
ActiveTasks int32 `protobuf:"varint,4,opt,name=active_tasks,json=activeTasks" json:"active_tasks,omitempty"`
}
func (m *HealthCheckResponse) Reset() { *m = HealthCheckResponse{} }
func (m *HealthCheckResponse) String() string { return fmt.Sprintf("%+v", m) }
func (*HealthCheckResponse) ProtoMessage() {}
// =============================================================================
// Unimplemented types for proto compatibility
// =============================================================================
// Ensure proto compatibility
var _ proto.Message = (*AgentEndpoint)(nil)
var _ proto.Message = (*A2AMessage)(nil)
var _ proto.Message = (*SubmitTaskRequest)(nil)
var _ proto.Message = (*SubmitTaskResponse)(nil)
var _ proto.Message = (*GetTaskRequest)(nil)
var _ proto.Message = (*TaskStatusResponse)(nil)
var _ proto.Message = (*ListTasksRequest)(nil)
var _ proto.Message = (*ListTasksResponse)(nil)
var _ proto.Message = (*CancelTaskRequest)(nil)
var _ proto.Message = (*CancelTaskResponse)(nil)
var _ proto.Message = (*SendMessageRequest)(nil)
var _ proto.Message = (*SendMessageResponse)(nil)
var _ proto.Message = (*CapabilitiesResponse)(nil)
var _ proto.Message = (*CreateGroupRequest)(nil)
var _ proto.Message = (*CreateGroupResponse)(nil)
var _ proto.Message = (*JoinGroupRequest)(nil)
var _ proto.Message = (*JoinGroupResponse)(nil)
var _ proto.Message = (*LeaveGroupRequest)(nil)
var _ proto.Message = (*LeaveGroupResponse)(nil)
var _ proto.Message = (*DisbandGroupRequest)(nil)
var _ proto.Message = (*DisbandGroupResponse)(nil)
var _ proto.Message = (*ListGroupMembersRequest)(nil)
var _ proto.Message = (*ListGroupMembersResponse)(nil)
var _ proto.Message = (*HealthCheckResponse)(nil)

File diff suppressed because it is too large Load Diff