clawchain/x/agent/keeper/query_recent_activity.go
caelum0x db831658ab feat(agent): expand gRPC surface, tasks, intents, negotiations, IBC discovery
Adds full QueryServer/MsgServer gRPC services, task lifecycle handlers
(accept, checkpoint, complete, delegate), intent protocol, negotiation
system, IBC agent discovery, rate limiting, reputation adapter, and
comprehensive test coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 22:13:45 +03:00

36 lines
884 B
Go

package keeper
import (
"context"
"clawchain/x/agent/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (q queryServer) RecentActivity(ctx context.Context, req *types.QueryRecentActivityRequest) (*types.QueryRecentActivityResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
limit := req.Limit
if limit == 0 {
limit = defaultActivityLimit
}
all := make([]types.AgentActionRecord, 0)
err := q.k.AgentActions.Walk(ctx, nil, func(_ uint64, value types.AgentActionRecord) (bool, error) {
all = append(all, value)
return false, nil
})
if err != nil {
return nil, status.Error(codes.Internal, "failed to iterate agent actions")
}
start := 0
if uint64(len(all)) > limit {
start = len(all) - int(limit)
}
return &types.QueryRecentActivityResponse{Activities: all[start:]}, nil
}